Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onchange trigger 1

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
I have an onchange event on an input field. Is there anyway to trigger this if the field is updated by another piece of javascript? Here's an example of what I mean:

Code:
<script language="javascript">
	function ChangeIt(){
		var obj = document.getElementById('MyInput');

		obj.value='Hello!';
		}

	function ShowIt(){

		var obj = document.getElementById('MyInput');

		alert(obj.value);
		}

</script>

<input type="input" id="MyInput" onchange="ShowIt();"><br />
<a href="#" onclick="ChangeIt();">Click here</a>

I realise I can call the ShowIt function at the end of ChangeIt but the above is just an example and this would not work for my actual app. i.e. The onchange event can be dynamic.

Thanks

Nick
 
Maybe I miss something... is adding obj.onchange() at the end not good enough?
[tt] obj.onchange();[/tt]
 
tsuji, nope you weren't missing anything, I was!! Thanks for this, feel a bit foolish now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top