Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Calling a javascript from a button added by a InnerHTML

    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;

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    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>:

    Code:
    <script>
    function nav(){
    window.location = 'clientinfo.asp?action=thankyou';
    }
    </script>
    and then your call:
    Code:
    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.

  • Users who have thanked ohgod for this post:

    telmessos (09-26-2008)

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    thanks ohgod. you are great.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •