| | |
for validation - text box and drop down menu
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Now here your problem is that as soon as one of those conditions is met, you return something. When you return something, your function is over and it does not continue.
So, here is code that does work. See if you can manipulate it to fit your needs.
So, here is code that does work. See if you can manipulate it to fit your needs.
html Syntax (Toggle Plain Text)
<html> <head> <script language="javascript" type="text/javascript"> function validate() { dropdowns = document.forms['theForm'].category; newCatDrop = document.forms['theForm'].newcat.value; isThere = false; for (i = 0; i < dropdowns.options.length; i++) { if (dropdowns.options[i].value == newCatDrop) { alert(newCatDrop + " is in the list!"); isThere = true; } } //close for return isThere; } //close function </script> </head> <body> <form name="theForm" action="#" method="post" onsubmit="return validate()"> New category: <input type="text" name="newcat"><br> Select category: <select name="category"> <option value="0">0</option> <option value="9">9</option> <option value="12">12</option> <option value="23">23</option> <option value="cats">cats</option> <option value="dogs">dogs</option> </select> <br> <input type="submit" name="submitButton" value="Submit"> </form> </body> </html>
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Solved Threads: 0
I appriciate you taking the time to help me out the past few days. The funny thing is, the javascript was sooo close to what you gave me. So, thank you alot. It worked. Here's the new javascript snippet:
Thanks again.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var dropdowns = document.forms[0].category; var newCatDrop = document.forms[0].newcat.value; for (var i = 0;i < dropdowns.options.length;i++) { if (dropdowns.options[i].value == newCatDrop) { alert("Please enter a value that is not already in our database."); return false; } }
Thanks again.
•
•
Join Date: Dec 2006
Posts: 10
Reputation:
Solved Threads: 0
Oh, and here's another variation:
I added the
Thought I'd share that bit.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var dropdowns = document.forms[0].category; var newCatDrop = document.forms[0].newcat.value; for (var i = 0;i < dropdowns.options.length;i++) { if (dropdowns.options[i].value.toLowerCase() == newCatDrop.toLowerCase()) { alert("Please enter a value that is not already in our database."); return false; } }
toLowerCase() code so that it would dynamically convert the strings to lowercase so that the user can't put in "Drew", "DREW", "drew", or "DrEw", etc. This makes sure that the user can only put one version of "Drew" in. In other words, only one entry (non-case sensitive).Thought I'd share that bit.
Last edited by drewrockshard; Dec 16th, 2006 at 7:51 am.
![]() |
Similar Threads
- pass the value to the text box (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Vey hard problem.. no idea how to solve ???
- Next Thread: Project help please !!!!!
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate api automatically blackjack browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor dependent disablefirebug dom dropdown editor element engine events explorer ext file firehose flash form forms game google gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha media microsoft mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing pdf php player post progressbar rated regex runtime scroll search security session shopping size software sql star stars stretch synchronous text textarea tweet twitter unicode validation web website window windowsxp wysiwyg xspf \n





