Jump to content

Re-setting an onchange event


Recommended Posts

I'm trying to change an onchange event, and I've got the code to do it and it's (almost) working, but I'm having a little problem with variables. Using this code:

c2.onchange = function onchange(event) { replaceWord(inc1, (i - 1), r, (total - 1)) };

The variables int1, i, r and total have all been declared in the script I'm using with the above line, the problem is that instead of setting the new function with the values those variables contain, it sets the variable's names as a literal string so "inc1" become the parameter. The code (of actually setting the new onchange function) works, as if I tried alert('hi') it would work fine.Any solutions to this?

Link to post
Share on other sites

You may need to post more of your source code.Here's something that might help you spot your problem.Tested in IE, O, FF.

  <script type="text/javascript">    var test = 'test';    var i = 5;    var j = 6	function showThis(s, int) {		alert(s + ' ' + int);	}	function chgOnChange(id) {		document.getElementById(id).onchange = function() { showThis(test, j - i); };	}  </script> </head> <body>	<input type="text" id="t1" value="test this" />	<script type="text/javascript">chgOnChange('t1');</script>

Link to post
Share on other sites
I'm trying to change an onchange event, and I've got the code to do it and it's (almost) working, but I'm having a little problem with variables. Using this code:
c2.onchange = function onchange(event) { replaceWord(inc1, (i - 1), r, (total - 1)) };

Try this instead:
c2.onchange = new Function(replaceWord(inc1, (i - 1), r, (total - 1)))

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...