jfourman Posted August 20, 2006 Share Posted August 20, 2006 I'm hacking at an ecommerce template to make some minor customizations.I am having trouble validating the value of a radio button in a form. I can print the value in the PHP code and it displays correctly. I just don't know how to write the "if" statement in the script to evaluate the value.The code below is just a test to display an alert message; but if the "Image Upload" button is selected, it doesn't display the alert. Do I need to do a string function on the "updatetype" variable first? The printf statement prints "Image Upload". I get the script and form to work if I am testing the value of a text box input. It's the radio button that is giving me problems.Script: (I left out the JS header since my message wouldn't post with it included):<!--function checkform(theForm){ if (theForm.updatetype.value == "Image Upload") { alert("<?php print "Radio Button is Image Upload."?>"); return (false); } return (true);}//--></script><form action='orderupdate.php' method="POST" onsubmit="return checkform(this)"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><input type="radio" name="updatetype" value="<? echo("Image Upload"); ?>"> Upload an image</label></td> </tr> <tr> <td><input type="radio" name="updatetype" value="<? echo("Change Request"); ?>"> Request a change to my order</label></td> </tr> <tr> <td><input type="radio" name="updatetype" value="<? echo("Cancellation Request"); ?>"> Cancel my order</label></td> </tr> <tr> <td> <input type='submit' name='send' value='Send Order Update'> </td> </tr> </table></form><?php printf ($updatetype);?>Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/18113-js-script-for-form-validate-cant-evaluate-radio-button-result/ Share on other sites More sharing options...
radalin Posted August 21, 2006 Share Posted August 21, 2006 Try giving an id to your updatetype's like instead of only names like:<input type="radio" name="updatetype" id="updatetype" value="<? echo("Change Request"); ?>"> Link to comment https://forums.phpfreaks.com/topic/18113-js-script-for-form-validate-cant-evaluate-radio-button-result/#findComment-77933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.