PDA

View Full Version : Set radioBtn value from url query (JS)


Paul Ferrie
08-27-2009, 01:27 PM
Hi Guys,

Quick question.
I am passing variables from a form to flash. Using the latest version of swfObject i am able to use:


var flashvars = {};
if(swfobject.getQueryParamValue("vs")){
flashvars.vs = swfobject.getQueryParamValue("vs");
}else{
flashvars.vs = "true";//Default
}
"vs" is set in a radio button group true/false

My question is how can i take the passed value on the form submitted to make sure when the page reloads the radio button group reflects that change. At present if i set to false and submit the form on page reload the radio button still says true.

yell0wdart
08-27-2009, 06:33 PM
What sort of server platform are you using? The DOM won't remember what values it has/had between posts alone. When the DOM gets unloaded, it's unloaded. When the page comes back from the post, it'll need to be set back to its previous state.

ASP.NET WebForms does this "auto-majically" via ViewState, though it can become pretty bloated on larger, more complicated forms.

ASP.NET MVC, PHP and old-school ASP will all need to manage that stuff manually.

jasonJ
08-27-2009, 06:36 PM
Without serverside, you could use a cookie (set with javascript) to store the value of the selected radio button. Remember though that a typical browser (IE7, FF3) stores up to 50 cookies per domain.

As a side note, there's an interesting DOM storage mechnism coming soon (as a part of HTML 5).
Here's an excerpt form Professional Javascript for Web Developers, 2nd ed, 2009:

DOM Storage has been partially implemented by Firefox 2 and later, and fully
implemented in IE 8 and Safari 3.1. Chrome is expected to implement it before
reaching version 1.0, and Firefox is expected to complete its implementation in
version 3.1.

Paul Ferrie
08-28-2009, 09:35 AM
Thanks for the input. i was only looking to setup a local player for a client with some debug options to test the project i am working on so no biggy to go into anything major. will just have to tell the client to edit the html file to set debug options.

Thanks again.