Jump to content

JS Script for Form Validate - can't evaluate radio button result


jfourman

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.