简体   繁体   中英

Weird behaviour with change event in HTML

I have a struts tag like this

<s:select label="Select Item" name="select3ph3meter1" id="select3ph3meter1" 
    headerKey="0" headerValue="-- Please Select --" list="meterHeaderList"
    required="true" onchange="show_3ph3meter1(this.value)"  />

The problem is it is not calling the above function on change event. It works when I change the code to this:

... onchange="alert('calling')"

I can't understand what's happening here.

Here is the JavaScript function:

function show_3ph3meter1(select3ph3meter1) {
    $("#3ph3meter1").load("meterFiller3p31.action",{select3ph3meter1:select3ph3meter1});
}

function show_depotReceipts(selectrecitem) {
    $("#recQuantity").load("depotRecQ.action",{selectrecitem:selectrecitem});
    $("#recRange").load("depotRecRange.action",{selectrecitem:selectrecitem});
}

The adjacent function is working perfectly so I assume there is no JavaScript error.

Also, when I put in another function (for instance the adjacent function name in onchange ), it is also working. The problem may be with this particular function name show_3ph3meter1() .

  1. First check your calling function name
  2. if this is correct then just write

    onchange="javascript : show_3ph3meter1(this)"

and get value on the function

3 else try the access value in function with selector

var elem = document.getElementById("short_code"),
selectedNode = elem.options[elem.selectedIndex]; 
var valu = selectedNode.value;

Hi if you have some other java script written over there contains errors , this code wont work.

So better have like this

<select class="style" onchange="//do something like this
 //var e = document.getElementById('selectelement'); //if (e) e.value=100;" />

please check in IE browsers to get the java script errors. write entire code in that change event

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM