Re: Using onchange in HTML
onChange is the event here. That is when the text in the inputbox is changed, the onChange event is fired.
If you pass "this" as parameter, then it refers to that element itself. Then you can access it in the function.
Here's an example:
HTML Code:
<html>
<body>
<input type="text" name="MyTextbox" size="40" value="" maxlength="160" onchange="myFunction(this)" />
<script language="javascript">
function myFunction(ele)
{
alert(ele.value);
}
</script>
</body>
</html>
To test it live: http://jsfiddle.net/wrFUD/
Type something in the box, and click somewhere outside the box. You'll get an alert box with the content of the inputbox.
:wave:
Re: Using onchange in HTML
I already know about passing this but that is not what my problem is. The call passes event. That is what I am dealing with not this .
Re: Using onchange in HTML
I believe it addresses that event (in your case the change event).
You could check that by alerting variablename.type
Example:
Code:
<input type="text" name="MyTextbox" size="40" value="" maxlength="160" onchange="myFunction(event)" />
<script language="javascript">
function myFunction(ele)
{
alert(ele.type);
}
</script>
:wave:
Re: Using onchange in HTML
The onChange happens whenever anything changes the value of the field, not just when the user enters a value. If a field's onChange changes the value of the field, it's easy to get an endless loop. In situations like this, be sure to check if the change needs to happen. For example, this product order form makes sure that the "total" field is always the correct total (even if the user changes it). The subtotal field "vn_stVis" uses onChange to check if it is different than the hidden subtotal field "vn_stHold". If there is a difference, vn_stVis is reset, which then causes another onChange event. However, that second time around the two fields are the same, and the script ends.