View Full Version : Calling a javascript from a button added by a InnerHTML

09-26-2008, 08:16 PM
Hi All,

I would like to learn if it is possible to run a javascript function from a button put by an InnerHTML

The code follows is the code working on my web site. It successfully puts the Submit button but does not make the redirection on submission of the form. Is there a way to do it ?

var mesaj2 = "<input type=\"submit\" value=\"Go To Payment Page\" onclick='window.location = clientinfo.asp?action=thankyou>'"
document.getElementById("submitarea2").innerHTML = mesaj2;

09-26-2008, 09:35 PM
first, you have errors. your closing > is on the wrong side of the function's closing quotes.

secondly, i know firsthand from recent experience that if nothing else, ie gets pissy if you alter the dom manually like that and then try to do things. it guess it might work, i'm just gunshy after a lot of troubleshooting lately.

however, i also learned that you just leave the function in an untouched part of the page and that you CAN drop new calls to the function in.

so, in the <HEAD>:

function nav(){
window.location = 'clientinfo.asp?action=thankyou';

and then your call:

var mesaj2 = "<input type=\"submit\" value=\"Go To Payment Page\" onclick=\"nav();\">'"
document.getElementById("submitarea2").innerHTML = mesaj2;

obviously it would be altered to handle bunches of locations, depending on what you need.

09-26-2008, 09:53 PM
thanks ohgod. you are great. ;)