TRI0N Posted May 20, 2007 Share Posted May 20, 2007 Okay trying to validate these 2 sets of buttons that each have 10 options that range from 1-10, sand_1 and sand_2 in a form with the id and name of "step1". <SCRIPT language="JavaScript"><!-- //script hider function form_validator(step1) { if(step1.sand_1.checked == false) { alert("<?php echo $txt_missing_sand_1 ; ?>"); step1.sand_1.focus(); return(false); } if(step1.sand_2.checked == false) { alert("<?php echo $txt_missing_sand_2 ; ?>"); step1.sand_2.focus(); return(false); } return (true); } // end script hiding --></SCRIPT> Something is not right... Quote Link to comment Share on other sites More sharing options...
TRI0N Posted May 21, 2007 Author Share Posted May 21, 2007 Either everyone is out of town or my script is so far off that it kinda makes people fall off their chairs laughing.. J/K Seriously though. Trying to find the cure for checking if a Radio Button is selected onr not. Quote Link to comment Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 id say give a shot at alert()ing the properties of sand_1 and sand_2, to see whether their properties even exist. i also believe a radio button input element will have no value until selected - you may be able to simply check whether the element's value property is null or not? Quote Link to comment Share on other sites More sharing options...
TRI0N Posted May 21, 2007 Author Share Posted May 21, 2007 Well I know the properties exist since I built the order form before adding in the validation script and know that if you don't select those options they will be null and if you selct one of the options it will be the number that its value is represented. But perhaps I'm being a bit too picky about having the first step with no default value. Using step1.sand_1.value == "" does not seem to catch it as NULL either and will proceed to step 2 if nothing is checked. Radio Buttons are still a pain in the butt compared to check boxes but simplify all the base scripting of writing either a inline java script that will uncheck one option if another option is selected in a series or using check boxes using the same idea. Was hoping there was a cure for the Radio Button problem with no default select button checked. I'll check back here but will begin to toy with other options on the matter. Thanks for your comments akitchin... Quote Link to comment Share on other sites More sharing options...
akitchin Posted May 21, 2007 Share Posted May 21, 2007 what i meant by alert()ing the properties was trying to see whether it's your code's logic, or just some syntax error. the first conditional will always be false if step.sand_1 isn't even referring to the element: function form_validator(step1) { alert("step1 refers to a: "+step1); alert("step1.sand_1 refers to a: "+step1.sand_1); alert("step1.sand_1.checked is: "+step1.sand_1.checked); alert("step1.sand_1.value is: "+step1.sand_1.value); if(step1.sand_1.checked == false) { alert("<?php echo $txt_missing_sand_1 ; ?>"); step1.sand_1.focus(); return(false); } if(step1.sand_2.checked == false) { alert("<?php echo $txt_missing_sand_2 ; ?>"); step1.sand_2.focus(); return(false); } return (true); } debugging your vars like this is always a good idea just to check whether it's actually your logic (ie. function returns and program flow) that's wrong, or simply a conditional that's written improperly. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted May 21, 2007 Author Share Posted May 21, 2007 Well I put that in and I get the following in order: step1 refers to a: [object] step1.sand_1 refers to a: [object] step1.sand_1.checked is: undefined step1.sand_1.value is: undefined I get those results even if I have sand_1 checked or unchecked. Should be saying the value is 5 when checked on the 5th object. The value is there once it passes thru to step 2 using: <?php $sand_1 = $_REQUEST["sand_1"]; echo $sand_1 ; ?> So I know the value is pass thru but the validation of the radio button is not returning results. 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.