Jump to content

Select Button Validation


ainoy31

Recommended Posts

I have a drop down menu where my client makes a selection and then click in the select button.  The info is pulled from a database.  What is the best way to validate that the user chooses a record and then clicks on the select button.  I do not want user to just click on the select button without making a selection in the drop down menu.  Hopefully this is not confusing.  I am using PHP.

 

Much appreciation.

 

AM

Link to comment
Share on other sites

JavaScript was designed for this kind of thing.  Write a JS script to check that the user has selected something, failing to submit unless a selection has been made.  Of course, users can turn off JavaScript or use a browser without it, so you'll also need to check for submitted data in PHP.  Just check that $_POST['your_select_name'] is set to some (legal) value.  If no value is set, or value is out of range or illegal, redisplay the page with an error message prompting the user to choose something, and include the form again.

Link to comment
Share on other sites

This is what I have:

 

<script text = "text\javascript" language = "javascript">

<!--

 

function SelectCustomer()

{

if(document.PendingCustomerInfo.Select.value)

{

alert("Please select a customer.");

return false;

}

return true;

}

//-->

</script>

 

Do I set the value to something?

Link to comment
Share on other sites

You should be using a not (!) condition (or reverse your conditions).

if (! document.PendingCustomerInfo.select.value) {
alert("Please select a customer.");
return false;
} else { return true; }

// Or

if (document.PendingCustomerInfo.select.value) { return true; }
else { alert("Please select a customer."); return false;}

 

What's the onSubmit code in your form?

 

It should be something like:

 

<form .... onSubmit="return SelectCustomer()">

 

Also, you're supposed to use the "/" slash in "text/javascript."

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.