Click here to Skip to main content
15,867,997 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written a jQuery program and inserted it into my Page1.aspx file. js-url.js resides in the Scripts file in the base folder. I have a website coming into this page:

http://www.mypage.com/Page1.aspx?var1=123&var2=987

This jQuery code is suppose to extract the variables var1 and var2 from the url and place them into TextBox1 and TextBox2 respectively. I am not sure if js-url.js is the correct script.

If someone knows a better or the same way to extract these variables please show me.


VB
<script src="../Scripts/js-url.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function() {
                var GET1=$("#TextBox1");
                var GET2=$("#TextBox2");
                GET1.val($.url("?var1"));
                GET2.val($.url("?var2"));
            });
        </script>
Posted
Comments
Sergey Alexandrovich Kryukov 26-Feb-13 17:45pm    
You don't show any "GET methods" here... .url is jQuery url parser, and your GET1 and GET2 are just variable assigned to some element wrappers...
—SA
Teledextri 26-Feb-13 18:10pm    
Either the jQuery url parser Method or a GET type method would solve my problem.
ZurdoDev 26-Feb-13 19:51pm    
So, does it work?
Teledextri 26-Feb-13 19:56pm    
No the above code does not work.

1 solution

If you are trying to get parameter values from querystring and you are already using JQuery, then you can try out this plugin which will get q-string params for you.

jQuery-URL-Parser

I haven't tried it , but it seems it will work for you in the following format...

JavaScript
var var1ParamResult = $.url('http://www.mypage.com/page1.aspx?var1=123&var2=987').param('var1');


The value '123' should be inside var1ParamResult variable. If the plugin doesn't work for you, there are methods that can do what you need using vanilla JS and regular expressions to sift through the url of the page.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900