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>

Link to comment
Share on other sites

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>

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.