Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown onchange function into html

I want to use Dropdown onchange function into html to pass value, it works fine in submit button, But I want to use Dropdown onchange, Pls help how to do it?

<form method="post" action=" ">
    <div align="center">
        <select name="value">
            <option value="">Show Value</option><br />
            <option value="2"> 2  </option><br />
            <option value="5"> 5  </option><br />
            <option value="10"> 10 </option><br />
            <option value="20"> 20 </option><br />
        </select>
        <input type="submit" name="submit" value="Submit">
    </div>
</form>
like image 628
Jeniffer Avatar asked May 03 '12 20:05

Jeniffer


People also ask

How do I use Onchange for dropdown?

Use the onchange Function to Create a Dropdown in JavaScript Here onchange function is declared with jsFunction(this. value); . The external file of JavaScript for the above HTML code is below. You can see the work of the onchange function handling in the above code from this link.

How do you call Onchange in HTML?

The onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.

Can we use Onchange in select tag?

Detect onChange Event of the select Element in JavaScriptThe change event is raised for input , select , and textarea when the user commits a change to the element's value. Unlike the input event, the change event doesn't necessarily fire every time the value of an element changes.

How do I pass value to Onchange?

To pass multiple parameters to onChange in React:Pass an arrow function to the onChange prop. The arrow function will get called with the event object. Call your handleChange function and pass it the event and the rest of the parameters.


1 Answers

you should add the onChange to the <select> element like this

<form method="post" action=" ">
    <div align="center">
        <select name="value" onChange="this.form.submit()">
            <option value="">Show Value</option><br />
            <option value="2"> 2  </option><br />
            <option value="5"> 5  </option><br />
            <option value="10"> 10 </option><br />
            <option value="20"> 20 </option><br />
        </select>
        <input type="submit" name="submit" value="Submit">
    </div>
</form>
like image 164
GuZzie Avatar answered Sep 23 '22 05:09

GuZzie