tags:

views:

196

answers:

4

Hi,

Using javascript, how do I add some data to the query string?

Basically I want to add the window.screen.height and window.screen.width info to the query string so that I can then email it with the other login info.

Alternatively, how would I populate a couple of hidden fields with the same data, a form is being submitted so I could pick it up from there?

Thanks, R.

A: 

for hidden fields, give each field an ID then do this

$("#fieldID").attr("value") = someValue;

UPDATE: Sorry, I saw Query and that made me think jQuery.

gargantaun
jQuery is nice, but it will require jQuery :).
Jimmy Chandra
+1 to get back to 0
Daniel
still not valid as you would need quotes around #fieldID
Jonathan Fingland
+5  A: 

I think that the latter option would be easier to implement. For example, if you have the hidden fields like this:

...
<input type="hidden" name="screenheight" id="screenheight" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" />
...

Then the JavaScript would be:

<script type="text/javascript">
document.getElementById('screenheight').value = window.screen.height;
document.getElementById('screenwidth').value = window.screen.width;
</script>
Bravery Onions
Thanks, I did go with the hidden fields and javascript combo and it worked out really well. Thanks.
flavour404
I'm happy that worked out for you. Please mark as answer if you feel like it.
Bravery Onions
+1  A: 

You can also use jquery.query.js to play with querystring.

TheVillageIdiot
A: 

If you wanted to add it to the location in a library agnostic manner, you could do the following:

var query = window.location.search;
var sep = "?";
if (query) {
   sep = "&";
}
window.location = window.location + sep + "h=" + 
    window.screen.height + "&w=" + window.screen.width;

This of course assumes that you don't have w or h parameters in the query string already.

seth