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
How to Programmatically Set the Value of a Select Box Element Using JavaScript
Is There a Spec That the Id of Elements Should Be Made Global Variable
Get Dom Content of Cross-Domain Iframe
Submit Two Forms With One Button
What Does "./" (Dot Slash) Refer to in Terms of an HTML File Path Location
Get File Size, Image Width and Height Before Upload
Jquery Document.Createelement Equivalent
How to Get Value of Selected Radio Button
How to Store Objects in Html5 Localstorage
How to Show the "Are You Sure You Want to Navigate Away from This Page" When Changes Committed
Custom Attributes - Yea or Nay
Get Class List For Element With Jquery
How to Move an Element into Another Element
How to Prevent Form from Being Submitted
Jquery Mobile: Markup Enhancement of Dynamically Added Content
Download File Using an Ajax Request
Why Calling Setstate Method Doesn't Mutate the State Immediately
How to Perform a Real Time Search and Filter on a HTML Table