Im new to JavaScript and I have traced problems I have been having to this. Can you tell me what Im doing wrong.
Works
if( document.myform.box1.checked ){
document.write( "true
" );
} else {
document.write( "false
" );
}
Prints
true
Works
if( document.myform.box2.checked ){
document.write( "true
" );
} else {
document.write( "false
" );
}
Prints
true
Works
if(true){
document.write( "true
" );
}
else{
document.write( "false
" );
}
if(false){
document.write( "true
" );
}
else{
document.write( "false
" );
}
Prints
true
false
Doesnt Work
if( document.myform.box1.checked ){
document.write( "true
" );
} else {
document.write( "false
" );
}
if( document.myform.box2.checked ){
document.write( "true
" );
} else {
document.write( "false
" );
}
Prints
true
The first 3 print what you would expect, the last only prints the first line. It wont print both true/false messages. Any ideas why?
2007-03-21
15:04:22
·
2 answers
·
asked by
rsmith985
3
in
Computers & Internet
➔ Programming & Design
I found a work around but I am still kind of curious why it fails. I found that you can do this.
var temp = "";
if(document.myform.box1.checked){
temp += "1true";
}
if(document.myform.box2.checked){
temp += "2true";
}
document.write(temp);
2007-03-21
16:10:59 ·
update #1