Jump to content


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

  • Please log in to reply
1 reply to this topic

#1 jfourman

  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 20 August 2006 - 04:05 PM

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);

<form action='orderupdate.php' method="POST" onsubmit="return checkform(this)">
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <td><input type="radio" name="updatetype" value="<? echo("Image Upload"); ?>">
              Upload an image</label></td>
            <td><input type="radio" name="updatetype" value="<? echo("Change Request"); ?>">
              Request a change to my order</label></td>
            <td><input type="radio" name="updatetype" value="<? echo("Cancellation Request"); ?>">
              Cancel my order</label></td>
  <input type='submit' name='send' value='Send Order Update'>
        printf ($updatetype);

Thank you for your help.

#2 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 21 August 2006 - 08:08 AM

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"); ?>">
Roy Simkes
Yet Another Parkyeri Developer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users