|
-
Jun 13th, 2012, 09:07 AM
#1
Using onchange in HTML
In the below HTML code I have a onchange="myFunction(event)" and I have a function called myFunction
My first question is what does the word event mean in the function call and my second question is what is the argument that I need in the function argument list.
Code:
<html>
<body>
<input type="text" name="MyTextbox" size="40" value="" maxlength="160" onchange="myFunction(event)">
<script language=javascript>
function myFunction(what_goes_here?)
{
//
// how to process the argument?
//
}
</script>
</body>
</html>
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 14th, 2012, 11:40 PM
#2
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 15th, 2012, 12:31 AM
#3
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 .
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 15th, 2012, 12:37 AM
#4
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>
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Dec 6th, 2012, 04:02 AM
#5
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|