Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting java to recognize radio buttons checked

Status
Not open for further replies.

Pattycake245

Programmer
Oct 31, 2003
497
CA
I am trying to get java to see that a radio button is checked but it doesn't "see" it. It is a Cold Fusion app and there are a set of three buttons all with the same name but different values. When a radio button is selected and the form is submitted it is supposed to load the same page again, but with the radio button that was checked to still be checked and the other two buttons disabled. But what it is doing is disabling all of them because it is not recognizing that I have checked one of the buttons. Does this make any sense?

In it's simplest form, this is what my form looks like:

function doRadioCheck()
{
for(x=0;x<frm_monitor.elements.length;x++){
if(frm_monitor.elements[x].name.indexOf("rsch_sel") != -1){
if (frm_monitor.elements[x].value!="" && frm_monitor.elements[x].checked==true)
{
<cfset request.chk="CHECKED">
<cfset request.edit="">
}
else
{
<cfset request.chk="">
<cfset request.edit="DISABLED">
}}}
</cfif>
}


<form name="frm_monitor" action="mon_entry.cfm" method="post">
<table border align="center">
<tr>
<td Valign="left"><input type="radio" name="rsch_sel" value="VG" doRadioCheck() #request.chk# #request.edit#>#disp_vg#</td>
<td Valign="left"><input type="radio" name="rsch_sel" value="G" doRadioCheck() #request.chk# #request.edit#>#disp_g#</td>
<td Valign="left"><input type="radio" name="rsch_sel" value="NI" doRadioCheck() #request.chk# #request.edit#>#disp_ni#</td>
</tr>
</table>

<cfoutput><input type="submit" onClick="return doFormSubmit(this.form)">

<cfoutput>
</form>

Is this even possible or am I barking up the wrong tree here?

thanks, Tim
 
It is possible but it seems your function only looks at teh radio buttons that are already checked
Code:
 if (frm_monitor.elements[x].value!="" && [b][COLOR=blue]frm_monitor.elements[x].checked==true[/color][/b])
shouldn't you check all of them?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Oh, look at that, good point! Didn't even notice that. Yes you are right I do need to check each one and if it is checked, check it, else disable it. What would the syntax be then?

Tim
 
I don't do coldFusion but here is what it would look like in ASP (no javascript used at all - all logic is server-side)
Code:
<tr>
<%
  select case request("rsch_sel")
    case "VG"
      response.write "<td><input type=radio name='rsch_sel' value='VG' CHECKED></td>"&_
        "<td><input type=radio name='rsch_sel' value='G'></td>"&_
        "<td><input type=radio name='rsch_sel' value='NI' ></td>"
    case "G"
      response.write "<td><input type=radio name='rsch_sel' value='VG'></td>"&_
        "<td><input type=radio name='rsch_sel' value='G' CHECKED></td>"&_
        "<td><input type=radio name='rsch_sel' value='NI' ></td>"
    case "NI"
      response.write "<td><input type=radio name='rsch_sel' value='VG'></td>"&_
        "<td><input type=radio name='rsch_sel' value='G'></td>"&_
        "<td><input type=radio name='rsch_sel' value='NI' CHECKED></td>"
    case else
      response.write "<td><input type=radio name='rsch_sel' value='VG'></td>"&_
        "<td><input type=radio name='rsch_sel' value='G'></td>"&_
        "<td><input type=radio name='rsch_sel' value='NI'></td>"
  end select
%>
</tr>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Pattycake-

I'm a little confused. This looks like JavaScript with nested CFML, which is quite interesting to me.

Are you sure this is what you want, and not straight JavaScript?

mwolf-

I'm not sure if you had the chance to see before those posts got correctly deleted, but I want to thank you again for your kind words and recognition. It was much appreciated.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
cLFLaVA - I didn't read flag them because I thought that the user was just confused - but I was VERY close to red flagging the ungrateful response that you received. It is not unusual to have a cross-forum posts between ASP or ColdFusion and JavaScript since both are often used together. Should this post be in the ColdFusion forum? Probably, since users there are more likely to have been exposed to this kind of thing. The posts to which you are referring were purely ASP and really were in the wrong forum altogether(as you pointed out).

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
I had red flagged them as well. As for this post, it seems it's in the correct forum, I'm just not sure what the asker is asking. There is CFML nested inside of JS, and I'm not familiar with CFML, so am trying to get clarification.

p.s. i had red-flagged them as well - there's no need to a) lash out in that manner and b) post the same question 3 times in a matter of 30 minutes.

thanks again.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
cLFLaVA -

I have nested ASP in JavaScript before
var msg = "<%=request("message")%>";
or some such thing.

But from what I remember of ColdFusion, it more intuitive and can be embedded more. I think that my solution would work fine in ASP but it may be cumbersome for a ColdFusion programmer - I'm not sure.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
You know what guys, I think I will do it the way mwolf00 showed. I kind of had something like that before but I wanted to try it with javascript. I thought I could use Cold Fusion variables inside the javascript code and attach those to all input fields but it is more pain to do it this way, and possibly slower than just using case statements in CF.

Thanks for the help. Those red-flagged posts aren't something I did are they?

Tim
 
Those red-flagged posts aren't something I did are they?

No, another thread earlier today...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
No Pattycake, no worries :)

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top