Jump to content

Recommended Posts

Hi

I have a simple form which contain a drop down menu for quantity.

After quantity is selected a script does a cost calculation and value is shown.  However the user should not be able to proceed without selecting quantity.  I am getting all sorts of illogical outcomes after each change or correction I make.

Initially the validation would just ignore the Quantity and check the second item.

Then after some changes to the code, now it keeps asking for Quantity even after the user has selected from the list.

Here is the code, do you see any errors?  Thanks in advance.

 

print "<script>
function validateForm()
    {
    let xss = document.forms[\"frmCustomize\"][\"SQty\"].value;
    if (xss == \"0\")
        {
        alert(\"Please select quantity\");
        return false;
        }    
    var fffnnn = document.forms[\"frmCustomize\"][\"CCnumber\"].value;
    if (fffnnn == null || fffnnn == \"\")
        {
        alert(\"Please enter your card number.\");
        return false;
        }

</script>";

 

the form :

print "<form action=M1.php method=POST id=C4 onsubmit=\"return validateForm()\" name=frmCustomize>";

 

// **************** QUANTITY *******************
print "<tr><td valign=top><b>Quantity:</td>

<td valign=top>
<select name=SQty id=SQty onchange=\"CalculateTotal()\">
<option value=0>Please select quantity</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option></select></td></tr>";

 

 

 

 

 

Edited by PHP5000
Link to comment
https://forums.phpfreaks.com/topic/325634-solved-form-validation-works-funny/
Share on other sites

  • PHP5000 changed the title to Solved - Form validation works funny

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.