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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass values between programs that link with buttons 2

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
hi,
i have an app that has a button like this:
<img src="c:\upd.jpg" onclick="return OnButton1();"></img>
when the button is clicked, it executes this javascript that goes to another page called update.asp:
Code:
function OnButton1()
{ 
  var msg = "update button was clicked!"; 
    document.Form1.action = "update.asp"  
    document.Form1.submit(Form1);  
    return true;
}
</script>
i like to be able to pass some values with this function. i understand that i can put it in a hidden field, since it submits a form. but i like to pass it from page to page using the above function.
thanks.

 
the value needs to be somewhere, either passed into the javascript function or in a hidden field and retrived by the javascript function. If it is a hidden field in "Form1" and is populated, it will be passed to the update.asp page by the submit event you are using. If you want to pass it as a querystring value to update.asp - pass the value to the function and attach it to the end of the url.

function OnButton1(strInput)
{
var msg = "update button was clicked!";
document.Form1.action = "update.asp?myParam=" + strInput
document.Form1.submit(Form1);
return true;
}
</script>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
If you're using asp you can get the hidden fields and act properly when generating the page.

If not, you can use something like

Code:
action = "update.asp?param=value"
[code]

but to be sincere I don't see the point. Maybe if you provide more details about what you're trying to do ...

Cheers,
[url=http://ferdiad.blogspot.com]Dian[/url]
 
thanks both.
my point is that i have to pass a variable that was entered in the main menu page (page1) as "code". the menu takes you to page2, page3, page4, etc. so, if someone just enters page3 on the address bar, since the code wasn't passed, i write a message that the authorized code is missing. that's the idea. i'm just trying to see how i can do this. any other ideas?

thanks.
 
on each page, you must be trying to grab the "code" from the previous page - when you do this, check to see if it is set....

What server side lanaguage are you using?


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
it's fairly easy in VBScript:

on index1.asp you have a hidden text field like this:

<input type="hidden" name="myVar" id="myVar" value="" />

on index2.asp, index3.asp and index4.asp, you check to see if it is set, if not you give the message and stop executing any more code...

<%
myVar = request.form("myFormField") ' or querystring
if myVar = "" or isNull(myVar) or isEmpty(myVar) then
response.write "not authorized"
response.end
end if
%>

If it was set and passed through via a post or get, you re-create the hidden text field with value of the var in the value attribute..

<input type="hidden" name="myVar" value="<%=myVar%>" />


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
thanks vicvirk.
i used a text field in index.asp (first page). i pass this as a form item to every page that it goes to. on each page, i access it by using request.form("kode"). if the code is not right, i use exactly the same message that you suggested. if page2.asp goes to page3.asp, then i populate the value of the hidden field with the code that i got from index.asp.
p.s. i'm using asp/vbscript.
thanks. it works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top