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!

Change the functionality of an event after it has already been set up

Status
Not open for further replies.

Webrookie

Programmer
May 18, 2000
112
US
ok

I have
<form name=&quot;entry&quot; method=&quot;post&quot; action=&quot;next.asp&quot;

<input type=&quot;button&quot; name=&quot;save&quot; value=&quot;Insert&quot; onClick=&quot;ShowPage('First','');&quot;>

now, later on in my code I want to change the first parameter of the ShowPage function for the onClick event.

document.entry.save.value=&quot;Update&quot;;
document.entry.save.onClick=&quot;ShowPage('Second','');

is this possible? To change what an event does after it's been declared? The value of the save button changes just fine, and I don't get a javascript error on the second line...but when click the button, it proceeds with the 'First' parameter instead of 'Second' as though it never executed...

any ideas?

 
I don't believe you can change the onClick parameter, you can however put the toggling in the function for both the value and the action:

<html>
<head>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
var c = 0;
var aShowAction = new Array(&quot;First&quot;,&quot;Second&quot;);
var aShowValue = new Array(&quot;Save&quot;,&quot;Update&quot;);
function ShowPage(vButton){
alert(aShowAction[c]);
// Increment or reset vCount
(c < aShowAction.length - 1) ? c++ : c = 0;

// Set the value of the button
vButton.value = aShowValue[c]
}

//-->
</SCRIPT>

</head>
<body>

<form name=&quot;MyForm&quot;>
<input type=&quot;button&quot; name=&quot;Save&quot; value=&quot;Save&quot; ONCLICK=&quot;ShowPage(this)&quot;>
</form>


</body>
</html>
- tleish
 
no, but, you could do this:

document.entry.save.onClick=function(){ShowPage('Second','');}
luciddream@subdimension.com
 
Ok, thanks guys...I'll mess around with it.....upsetting that i can't change what the event does...grrrrrrrr...like the way i want to.
 
btw...

document.entry.save.onClick

should be

document.entry.save.onclick luciddream@subdimension.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top