View Full Version : Checkbox value invalid?
elcaro2k
08-05-2003, 04:48 PM
I am aquiring a value from a page thats in an iframe from the parent using the following syntax:
frames.frame_name.document.form_name.elements.element_name
All inputs are correct except the checkboxes. They are always "On", no matter if they are checked or not? :confused: Any ideas?
Thanks,
Ray
Vincent Puglia
08-05-2003, 05:07 PM
Hi,
1) What does the html for the checkboxes look like, specifically the names?
2) what does the actual code look like -- are you hardwiring the names or looping?
Vinny
elcaro2k
08-05-2003, 09:17 PM
The names are hardcoded:
getStateRs()'returns Rs %>
<br>
<table name=ManRegTbl>
<tr><td align=right>DOI:</td><td align=left>
<Select Name=StDropDwn><%
Response.Write("<option value = 1>---- State ----")
do while Rs.EOF=false
Response.Write("<option value=" & Rs("state")& ">")
Response.Write(server.HTMLEncode(Rs.Fields("state")) & "</option>")
Rs.MoveNext
loop
Rs.Close
set Rs = nothing
%></Select></td>
<tr><td align=right>Medicare</td><td align=left><input type=checkbox name=Medicare> </td></tr>
<tr><td align=right>Medicaid:</td><td align=left>
<Select Name=StDropDwn2><%
getStateRs()'returns Rs
Response.Write("<option value = 1>---- State ----")
do while Rs.EOF=false
Response.Write("<option value=" & Rs("state")& ">")
Response.Write(server.HTMLEncode(Rs.Fields("state")) & "</option>")
Rs.MoveNext
loop
Rs.Close
set Rs = nothing
%></Select></td>
</tr>
<tr><td align=right>Medi-CAL</td><td align=left><input type=checkbox name=MediCAL></td></tr>
<tr><td align=right>Legal</td><td align=left><input type=checkbox name=Legal></td></tr>
<tr><td align=right>Other:</td><td align=left><input name=othrManRegTxt size=15> </td></tr>
Vincent Puglia
08-05-2003, 10:57 PM
Hi,
There is nothing wrong with html that I can see. So.... when you say 'on', do you mean checked? Is the javascript that you call in the main page or the iframe? When checking a checkbox's value, I use the following:
if (....document.formName.elements['chkboxName'].checked)
alert(....document.formName.elements['chkboxName'].value)
Vinny
cheesebagpipe
08-06-2003, 02:51 AM
The default value of all checkboxes (when you don't assign something else in your HTML) is 'on' - that's why you're seeing it. This is designed for HTML, where checked CBs submit data, unchecked ones don't. When scripting, you don't generally check a checkbox value, but whether the box has been checked (Checkbox.checked Boolean property); if it has, then the name/value pair is relevant. If you want a meaningful pair, give the boxes an explicit value:
<input type="checkbox" name="something" value="MediCAL">
<input type="checkbox" name="something" value="Legal">
<input type="checkbox" name="something" value="othrManRegTxt">
Note: the above get put in an array, necessitating a loop for programming reads.
elcaro2k
08-06-2003, 02:12 PM
Thanks.:thumbsup: The .checked property is the answer.
I really appreciate the help, thanks again!!!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.