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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Value Problem

Status
Not open for further replies.

ThomasE

Technical User
Nov 20, 2002
12
AU
I am trying to write the checkbox value into another popup window but it does not work in Netscape 7. I get an error in the javascript console saying.... ' document.all has no properties '. Below is an example of the section of code I am using.

list += &quot;</table>&quot;;
var nametitle = &quot;&quot;;
if(document.all.MR.checked) { nametitle = &quot;Mr.&quot;; }
if(document.all.MISS.checked) { nametitle = &quot;Miss.&quot;; }
if(document.all.MRS.checked) { nametitle = &quot;Mrs.&quot;; }

along with....

list += &quot;<html><body><font color='#ff9900' face='Verdana, Arial, Helvetica' size='2'>Title<br><font color='#000000' face='Verdana, Arial, Helvetica' size='2'><hr size=\&quot;1\&quot; width=\&quot;100%\&quot;>&quot; + &quot;Name: &quot; + nametitle + &quot;<br>&quot;;

Any help would be greatly appreciated.
 
Replace all &quot;
Code:
document.all.xx
&quot; that are IE specific by &quot;
Code:
document.getElementById(&quot;xx&quot;)
&quot; that is compatible with all latest browsers Water is not bad as long as it stays out human body ;-)
 
Thanks Targol,

list += &quot;</table>&quot;;
var nametitle = &quot;&quot;;
if(document.getElementById(&quot;MR&quot;) { nametitle = &quot;Mr.&quot;; }
if(document.getElementById(&quot;MISS&quot;) { nametitle &quot;Miss.&quot;; }
if(document.getElementById(&quot;MRS&quot;) { nametitle = &quot;Mrs.&quot;; }

I am still getting an error in the NS console saying

Error: missing ) after condition

I have also tried this....but get the same message

list += &quot;</table>&quot;;
var nametitle = &quot;&quot;;
if(document.getElementById(&quot;MR&quot;).checked={ nametitle = &quot;Mr.&quot;; }
if(document.getElementById(&quot;MISS&quot;).checked={ nametitle = &quot;Miss.&quot;; }
if(document.getElementById(&quot;MRS&quot;).checked={ nametitle = &quot;Mrs.&quot;; }

Can you tell me what is wrong with the code

Thanks
 
Can anyone please help with this problem as it is really urgent.......Thank You
 
Hi ThomasE
Please try the code below. It should work fine. I have added try catch code just to ensure it does not throw any error message.

var nametitle = &quot;&quot;;
function showTitle()
{
try{
if(document.getElementById(&quot;MR&quot;).checked == true) { nametitle = &quot;Mr.&quot;; }
if(document.getElementById(&quot;MISS&quot;).checked == true) { nametitle = &quot;Miss.&quot;; }
if(document.getElementById(&quot;MRS&quot;).checked == true) { nametitle = &quot;Mrs.&quot;; }
alert(nametitle);
} catch(e){}
}

However i don't know why are you using checkbox for this. Instead you should use radio buttons as at any given time a person will select either of one available choices (MR, MISS, MRS). Additional advantage of using radio buttons is that you don't have to use getElementById and look for checked, you can simply use radio button name to get the checked value.

Hope this will help you [bigcheeks] Experience teaches slowly and at the cost of mistakes [pipe]
 
Hey thanks Raxg,

If I use radio buttons do I need to use a list like below except with radio buttons or does it write the value like a text field or option box does?

list += &quot;</table>&quot;;
var nametitle = &quot;&quot;;
if(document.all.MR.checked) { nametitle = &quot;Mr.&quot;; }
if(document.all.MISS.checked) { nametitle = &quot;Miss.&quot;; }
if(document.all.MRS.checked) { nametitle = &quot;Mrs.&quot;; }

If I do not need to create a list like above how would the code be written.

Appreciate your help
 
<select id=&quot;nameTitle&quot; name=&quot;nameTitle&quot;>
<option value=&quot;Mr.&quot;>Mr</option>
<option value=&quot;Miss.&quot;>Miss</option>
<option value=&quot;Mrs.&quot;>Mrs</option>
</select>

 
palbano........is that HTML or is it the javascript code that I need to add into the script??

and do I need to add it into the lines of code that refer to the other text fields etc as shown below.

list += &quot;<html><body><font color='#ff9900' face='Verdana, Arial, Helvetica' size='2'>Title<br><font color='#000000' face='Verdana, Arial, Helvetica' size='2'><hr size=\&quot;1\&quot; width=\&quot;100%\&quot;>&quot; + &quot;Name: &quot; + nametitle + &quot;<br>&quot;;

thanks

 
Oh, thought you would get the rest.

Then your script would change to:

var nametitle = document.all.nameTitle.Value;

or

var nametitle = document.all.nameTitle[document.all.nameTitle.selectedIndex].Value;


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top