0

I would like a simple form for an employee to enter an order ID. That ID would be validated from a second input. When it is validated it would be passed to the database through the insert.php on the server.

Below is what I have written so far. I'm stumped on how to push the data on a successful check or clear the form on a fail.

<script type="text/javascript" language="JavaScript">
<!--
//--------------------------------
// This code compares two fields in a form and submit it
// if they're the same, or not if they're different.
//--------------------------------
function checkid(theForm) {
    if (theForm.orderid1.value != theForm.orderid2.value)
    {
        alert('The two values don\'t match! Please check!');
        return false;
    } else {
        return true;
    }
}
//-->
</script> 




<form action="../" onsubmit="return checkid(this);">
<form action="insert.php" method="post">

<p> Enter the compleated Order ID<br>
<input type="TEXT" name="orderid1" size="20" maxlength="20"> 
<br>
Please Confirm the order ID!
<br>
<input type="TEXT" name="orderid2" size="20" maxlength="20"> 
<br>
<input type="SUBMIT" value="Compleate Order!"></p> 
</form>
Captain Man
  • 5,651
  • 3
  • 41
  • 64
  • 1
    see this SO question and answer for an example of POST'ing using JavaScript : https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit – landru27 Oct 12 '18 at 18:52
  • 1
    why do u have 2
    ? form action="../" onsubmit="return checkid(this);">
    what is this?
    – Talg123 Oct 12 '18 at 18:54

1 Answers1

1

anyway this is the answer for you.

<script type="text/javascript" language="JavaScript">
<!--
//--------------------------------
// This code compares two fields in a form and submit it
// if they're the same, or not if they're different.
//--------------------------------
function checkid(theForm) {
    if (theForm.orderid1.value != theForm.orderid2.value)
    {
        alert('The two values don\'t match! Please check!');
        return false;
    } else {
        return true;
    }
}
//-->
</script> 




<form action="insert.php" onsubmit="return checkid(this);" method="post">

<p> Enter the compleated Order ID<br>
<input type="TEXT" name="orderid1" size="20" maxlength="20"> 
<br>
Please Confirm the order ID!
<br>
<input type="TEXT" name="orderid2" size="20" maxlength="20"> 
<br>
<input type="SUBMIT" value="Compleate Order!"></p> 
</form>
Talg123
  • 1,190
  • 1
  • 6
  • 14