Jump to content

can someone show how to validate input field with image submission


daredevil88

Recommended Posts

hi, I have created an a form with image submission button. how can I validate input field is empty or not?

here is the example of what I did

<html>

<body>

<form method="post" name="purchase_form" action = "order.php"

onsubmit="return validate_form(this)">

        <table>

<tr><th colspan = 2 bgcolor=#C6EFFY align = 'left'>Please enter your

delivery details</th></tr>

        <tr><td width=100>  <td><td> </td></tr>

  <tr><td><b>First Name: </b></td>

        <td><input type = 'text' name = 'firstname' maxlength = 30 size =

30></td></tr>

  <tr><td><b>Last Name: </b></td>

        <td><input type = 'text' name = 'lastname' maxlength = 30 size =

30></td></tr>

<td><input type="image" src="images/purchase.jpg"

        width="135" height="40" name="Purchase"></td>

  </table>

</form>

</body>

</html>

sorry, the function is here. I take this example from one of the forums but how can I add to validate more than one field to fit into this function?

 

<script type="text/javascript">

function validate_required(field,alerttxt)

{

        with (field)

        {

        if (value==null||value=="")

          {alert(alerttxt);return false}

        else {return true}

        }

}

function validate_form(thisform)

{

        with (thisform)

        {

        if (validate_required(firstname,"First Name must be filled out!")==false)

          {fristname.focus();return false}

        }

        with (thisform)

        {

        if (validate_required(lname,"Last Name must be filled out!")==false)

          {lastname.focus();return false}

        }

}

</script>

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.