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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing parameters from html to javascript

    I am trying to pass a value using a parameter in html (asp) to a javascript function. When I try to pass a value inside of a variable <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1(tst);"> it simply doesn't work (no error msg - just nothing) while if I put a value in the call <INPUT type="submit" value="Next Youth" name=button1 onclick="OnButton1('5393');"> it works fine. The javascript looks like this:

    function OnButton1(tst)
    {
    var pth = "youth_edit3.asp?cIndex=" + tst;
    document.YouthEdit.action = pth;
    document.YouthEdit.submit(); // Submit the page
    }

    I've set tst = "5393" but it won't work when I try to pass it. Only a literal value of '5393' works. What am I doing wrong? Thank you in advance.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question More information needed...

    What is or where does the variable 'tst' get set?
    How are you doing this?
    Have to checked to see if the value is being passed correctly to the function?

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Arrow

    Quote Originally Posted by Betty5767 View Post
    Have to checked to see if the value is being passed correctly to the function?[img]http://www.*****************/jh2.jpg[/img]
    [img]http://www.*****************/2.jpg[/img]
    [img]http://www.*****************/5.jpg[/img]
    Code:
    function OnButton1(tst) {  alert(tst);   // for testing purposes only
      var pth = "youth_edit3.asp?cIndex=" + tst; 
      document.YouthEdit.action = pth;
      document.YouthEdit.submit(); // Submit the page
    }

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't seem to matter but in the html part of the code - right before I have the onclick event I can do something like:


    <% tst = "5393" %>

    It doesn't matter. It won't pass.

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Betty5767

    I tried the alert to see the output and if I put '5393' in the call - onclick="OnButton1('5393') I get the alert message before it goes to the page I've requested. If I put tst in then nothing happens at all. And, this after I've set tst = '5393'. So, I'm confused.


  •  

    Posting Permissions

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