Forum Moderators: open
I can help you with the first part of your problem, namely resetting to "Select keyword", but some of the more experienced javascripters will have to help with the second. They'll be around I'm sure.
Add a name to your form as in: <form name=bobtheform ...>
And add this to your body tag: onLoad="document.bobtheform.reset();"
If I understand correctly you have multiple drop downs and want them only to pick a value in one and then hit a "go" button or something. If this is the case I would change to behaviour of the drop downs so that they "go" as soon as a value is selected allowing them to only make a single selection.
<select name="elementname" onChange="switchurl();">
or something like that
Here's an attempt at an event handler which, when you hit the submit button, will check every drop-down menu and sumbit the form if, and only if, exactly one item has been selected. The <form> tag should be written like this:
<form action="next.asp" onsubmit="return check(this);">
The script looks like this:
function check(f){
var num_selected=0;
for(var element in f.elements){
if(f.elements[element].type!='select-one') continue;
if(f.elements[element].selectedIndex>0) num_selected++;
}
if(num_selected==1) return true;
alert('You must select one item only');
return false;
}
It works by looping through all the elements of the form, skipping those that are not drop-down menus. For each drop-down menu, it checks that an item has been selected, and that it's not the first item (which would be your "Please select" line). If you don't have "Please select..." as your first line, you will need to change the condition to...
if(f.elements[element].selectedIndex>=0)...
(A value of 0 means "first item selected", a value of -1 means "no item selected"). Every time it finds a menu with an item selected, it increments the value of num_selected.
Having looped through the elements, it then tests to see how many items have been selected. If the answer is 1, the function ends and returns true, which causes the form to be submitted. Otherwise it pops up an error message and returns false, which cancels the submission process.
Personally, I think jatar_k's solution is the better one, but you can study this example anyway. (No guarantees, though; I haven't tried it out.)
Don't ditch the server-side test, though. Any client-side JavaScript solution relies on JavaScript being enabled, so you'll still need the server-side script as a fail-safe backup.
It sounds as if you are attempting the type of form that allows a user to make multiple selections similar the the job/category1/category2/region1/region2/keywords type form that jobsites such as Monster.com employ. I've never needed to create a form as sophisticated as this so I cannot speak from experience on this issue. Toadhall, jatar_k and rewboss have all offered some good options and I expect some other members may have other suggestions that may help you target a solution.
Once again.. welcome to the forums!