How to Pass Parameters on Onchange of HTML Select

How to pass parameters on onChange of html select

function getComboA(selectObject) {  var value = selectObject.value;    console.log(value);}
<select id="comboA" onchange="getComboA(this)">  <option value="">Select combo</option>  <option value="Value1">Text1</option>  <option value="Value2">Text2</option>  <option value="Value3">Text3</option></select>

Can I pass a select value as a param to an onchange function?

Just pass this as parameter, then get the value from it :

function myFunction(current_select){    alert( current_select.value );}
<select onchange="myFunction(this)">    <option value="op1">Op1</option>    <option value="op2">Op2</option>    <option value="op3">Op3</option></select>

Pass parameter from one select function to another using onchange event

First on the lstProveedor list add this onchange function

<select id="lstProveedor" class="form-control select2 select2-accessible" aria-hidden="true" onchange="getCuadrilla(this.value)"></select>

In your getCuadrilla(ID) have a parameter which will receive this selected ID

You can remove the onchange from the jsoncatalog attached to lstProveedor

How to pass parameters on onChange of html select with flask-wtf

It can be done by add javascript onchange function as attribute

<form method=post action="/register">
{{ render_field(form.country(**{"onchange":"this.form.submit()"})) }}
<input type=submit value=Register>
</form>

Passing both event and parameter to onchange bound function in JavaScript

I will explain what happens in the linked answer as you mentioned that you want to achieve the same behaviour.

So:

<fieldset onChange={(e) => this.props.handleChange("tags", e)}>

This React code attaches anonymous function with one parameter e to the fieldset as onChange listener. This function in its body invokes another function, passing e with additional parameters.

Translating this into your code, you would like to achieve something like this:

function update(e, attr) {
// e is instance of Event
// attr is additional parameter
}
document.getElementById("myelement").onchange((e) => update(e, attr));
// or without ES6 arrow function:
document.getElementById("myelement").onchange(function(e){ update(e, attr); });

Also, be advised that proper way of attaching event listeners is by addEventListner API.

How to pass two or multiple parameters in onchange event

            <select name="level" id= "level" onchange="changeLevel(this , '<?php echo $user->id?>');">

...


changeLevel = function(level, user_id){
...

Pass 2 parameters to OnChange in a select from the elements

You can't bound to object, meaning you can't bound to an Element object like this: value=@element. You can only bound to string values.

You may bound to element.Name which is string, like this:

<option value="element.Name">@element.Description</option>

Your SelectValueChange may look like this:

private void SelectValueChange (ChangeEventArags args)
{
var selectedName = args.Value.ToString();
}

parameter.Name and element.Name

What do you mean parameter.Name ?

Please show more code, if you still need help...

UPDATE

i'm fine with binding to element.Name . but i need to know the 'name' of this select. Because i got like 50 on the page. so i need to know the specific select the call is comming from. –

I'm not sure if I understand you... Do you mean that you've got 50 select elements on your page with a single SelectValueChange method, and you want to know from which select element your SelectValueChange method has been called? If so, the simplest way is to add another parameter identifying the select element. It can be done in various ways... The simplest way to do that I guess is as follows:

 @onchange="@((ChangedEventArgs args) => SelectValueChange(args, "Select1"))"

And your SelectValueChange may look like this:

private void SelectValueChange (ChangeEventArags args, string selectName)
{
var selectedName = args.Value.ToString();
}


Related Topics



Leave a reply



Submit