...

View Full Version : Passing parameters from html to javascript



plightstone
12-19-2011, 01:28 AM
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.

jmrker
12-19-2011, 01:48 AM
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?
:confused:

jmrker
12-19-2011, 02:27 AM
Have to checked to see if the value is being passed correctly to the function?http://www.*****************/jh2.jpg
http://www.*****************/2.jpg
http://www.*****************/5.jpg



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
}

plightstone
12-19-2011, 04:23 AM
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.

plightstone
12-19-2011, 04:31 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum