views:

72

answers:

3

I have two html pages example1.html and example2.html ,how can i pass a javascript variable username from example1.html to example2.html in querystring.

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>
+1  A: 

You could either use PHP, or set location.search.

Delan Azabani
I dont want to use serverside script ,just i want to retrieve those values in example2.html
mahesh
+1  A: 

You can modify the href attribute of your link:

$("#example2 a").attr("href", url + "?var1=" + username);

If username uses special characters you will need to url encode it.

kgiannakakis
Thanks for the reply, how do i retreive the username on example2.html page?
mahesh
You are welcome. See http://www.netlobo.com/url_query_string_javascript.html for your question.
kgiannakakis
+1  A: 

What about using cookies? http://plugins.jquery.com/project/Cookie - no need to modify query string :)

dmitko
Cookies are persistent and get sent with every request to the server.
David Dorward