angel777 Posted March 30, 2008 Share Posted March 30, 2008 hi.. i have asked this to javascript site here.. but no one reply.. i tried to put validation for radio button.. but fail.. if(!document.change.r1.checked== true) { window.alert('Please check the X- Ray facilities'); return false; ... } the change = my form name, r1 = radiobutt name it pop out ... but after i check the radio.. it still pop out Quote Link to comment Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 hi.. i have asked this to javascript site here.. but no one reply.. Then bump it. It doesn't make it a PHP problem Quote Link to comment Share on other sites More sharing options...
toplay Posted March 30, 2008 Share Posted March 30, 2008 I deleted his other topic and unlocked this one...moved it to JS help. Quote Link to comment Share on other sites More sharing options...
angel777 Posted March 30, 2008 Author Share Posted March 30, 2008 any answer for my question ? htanks Quote Link to comment Share on other sites More sharing options...
Barand Posted March 30, 2008 Share Posted March 30, 2008 <html> <head> <meta name="generator" content="PhpED Version 4.5 (Build 4513)"> <title>sample</title> <meta name="author" content="barand"> <meta name="creation-date" content="03/30/2008"> <script language='javascript'> function checkRB(form) { var k = form.elements.length; for (var i=0; i<k; i++) if (form.elements[i].name =="rb" && form.elements[i].checked==true) { return true; } alert("Not checked") ; return false; } </script> </head> <body> <form onsubmit="return checkRB(this)"> <input type="radio" name="rb" value="1"> 1 <input type="radio" name="rb" value="2"> 2 <input type="radio" name="rb" value="3"> 3 <br/> <input type="submit" name="sub" value="Do"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
sean14592 Posted March 31, 2008 Share Posted March 31, 2008 Hi, I can't seem to get that to work for me. I cannot put that in my header so I have put it just before the <form> tag and also changed name to the field name of the two fields in the group, So it looks like this: <script language='javascript'> function checkRB(form2) { var k = form.elements.length; for (var i=0; i<k; i++) if (form.elements[i].carnessary =="rb" && form.elements[i].checked==true) { return true; } alert("Not checked") ; return false; } </script> Quote Link to comment Share on other sites More sharing options...
angel777 Posted March 31, 2008 Author Share Posted March 31, 2008 thanks for the reply... but my problem is not on multiple checkbox with that for loop.. i wonder can i put like this ? if(!document.change.r1.checked== true) { window.alert('Please check the X- Ray facilities'); return false; } else {return true} Quote Link to comment Share on other sites More sharing options...
sean14592 Posted March 31, 2008 Share Posted March 31, 2008 This is doing my head in, answere is prob so simple. I ahve tried using: <script type="text/javascript"> <!-- function validate_form ( ) { valid = true; if ( ( document.form2.cult[0].checked == false ) && ( document.form2.cult[1].checked == false ) ) { alert ( "Please choose select yes or no!" ); valid = false; } return valid; } //--> </script yet, it still does not work! Cheers Sean Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.