View Full Version : Default to a radio button onclick or onload

06-07-2011, 10:39 PM
Hello I can't figure out how to code this. Right now I have 3 radio buttons edit/print/search. I need it to go back to the edit radio button either onclick or onload. Don't know what would be better. My codding looks like this so far:

<input type="radio" name="radiooption" value="Edit"<cfif #Session.radiooption# IS "Edit">CHECKED</cfif> onClick="this.form.submit();">Print<input type="radio" name="radiooption" value="Print"<cfif #Session.radiooption# IS "Print">CHECKED</cfif> onClick="this.form.submit();">search<input type="radio" name="radiooptione" value="search"<cfif #Session.radiooption# IS "search">CHECKED</cfif> onClick="this.form.submit();"></font>

<input type="button" name="ClearLabels" value="Clear Labels" style="font-size: 9px;" onClick="this.form.submit();">

What I need done in the end is when Clear Labels is clicked. I need it to clear the label que (which it does that now), but I need it to also go back to the edit radio (#Session.radiooption# IS "Edit") radio button. What would the best way to do this be?

06-08-2011, 02:19 PM
I don't know what <cfif> is so I have left them out of answer.
2. I put things in lower case because that's how their should be.
3. I am guessing, because you are submitting form for every action, that your page is being re-displayed all the time. So the answer is in the way the radio buttons are displayed:

Edit <input type="radio" name="radiooption" value="Edit" checked="true" onclick="this.form.submit();">
<br />
Print <input type="radio" name="radiooption" value="Print" onclick="this.form.submit();">
<br />
Search<input type="radio" name="radiooption" value="search" onclick="this.form.submit();">

06-08-2011, 05:18 PM
@sunfighter: If you don't know what <cfif> is, then you probably shouldn't answer questions in the ColdFusion forum :p However, good job on cleaning up that code...

@taunnt: What does your ColdFusion code look like that clears your label queue? Can you possibly just re-set session.radioOption back to "edit" when you clear your queue? (i.e. <cfset session.radioOption = "edit">)

Your HTML code should probably look like this in general though:

Edit <input type="radio" name="radioOption" value="Edit" onclick="this.form.submit();" <cfif session.radioOption eq "edit">checked="true"</cfif>><br />

Print <input type="radio" name="radioOption" value="Print" onclick="this.form.submit();" <cfif session.radioOption eq "print">checked="true"</cfif>><br />

Search <input type="radio" name="radioOption" value="search" onclick="this.form.submit();" <cfif session.radioOption eq "search">checked="true"</cfif>><br />

<input type="button" name="ClearLabels" value="Clear Labels" style="font-size: 9px;" onClick="this.form.submit();">


06-08-2011, 06:34 PM
Sorry. Didn't realize I was in Cold Fusion section :(

06-08-2011, 07:43 PM
Haha, all good man :)