Current Code:
<select name='PreviousReceiver' onchange='this.form.submit()'>
<option value='0'>Contact List</option>
<option value='1'>blah</option>
<option value='2'>blah2</option>
<option value='3'>blah3</option>
</select>
So I have this dropdown box that auto submits when the user clicks it. It works fine the way it is, but I dont want it to submit if the user has the first value selected(see above).
In other words, if the user clicks contact list, then I don't want it to submit the form.
I tried this:
onchange="if(this.value != '0') this.form.submit()"
but that just made it never activate.
Any suggestions?
Learn HTML A select box also called drop down box provides an option to list down various options in the form of drop down list. You can also preselect a value in dropdown list of items in HTML forms. For that, add selected in the <option> tag for the value you want to preselect.
The HTML Select DropDownList has been assigned a jQuery OnChange event handler. When an item is selected in the HTML Select DropDownList, the jQuery OnChange event handler is executed within which the Text and Value of the selected item is fetched and displayed in JavaScript alert message box.
To retain the selected value in the dropdown on refresh, sessionStorage is used to store the value within the user's browser. First, the values have to be set using sessionStorage. setItem("SelItem", selVal); SelItem is a variable in which we are setting the value of selVal .
If you have a Html (or Html5, JSP, PHP, ASP) page with a form element containing select option and you want to submit the form once a option is selected from the list of the dropdown then you can make use of javaScript.
A completely different alternative is to use <ul><li><input type="submit"> and throw in a load of CSS to make it look like a true dropdown list. But then there's no means of a <select> anymore. @deweydb "A lot of users block javascript…" Citation?
@deweydb: Nope. I would otherwise have answered it :) Just show a <noscript> banner that site's experience is better if JS is enabled. A completely different alternative is to use <ul><li><input type="submit"> and throw in a load of CSS to make it look like a true dropdown list. But then there's no means of a <select> anymore.
function DoSubmit (sel) { if (sel.val ()!='0') this.form.submit (); } maybe you would like something like this? This also disables the selection of the first item This is the same answer as mentioned above,You need to make it more clear or little different.
maybe you would like something like this? This also disables the selection of the first item
<select name='PreviousReceiver' onchange='this.form.submit()'>
<option selected disabled>Contact List</option>
<option value='1'>blah</option>
<option value='2'>blah2</option>
<option value='3'>blah3</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With