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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.