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

Setting a session variable with the OnClick event.

Status
Not open for further replies.

etjohnson81

Programmer
Jul 17, 2006
72
US
Anyone know how it can be done? I hate using the URL to pass information.

For example I have a table created from a query and each link is assigned a variable for the next page.
 
Is your intention to set the session variable w/o even navigating off the page? For something like this you would need to use javascript and a little AJAX. Googling for AJAX will bring up a ton of examples.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
AJAX is probably the way to go, but I'm curious, why do you hate passing information through URL?

-Kerry
 
and do you hate POSTing information with a form?
 
Thanks for the suggestions...the page navigates to another page and right now I am using the request.querystring. I just dont like to use it because its "dirty" looking, plus for my application it allows users to open a page without being logged in. I know, I need to add a log in check to all the pages.

SHECO... I was just thinking about a form, but Im not sure about how to use a link to submit the form, and then just use a hidden value.
 
Ok, well I wouldn't use the querystring, I would use the post method:

Code:
<form name="MyForm" action"bla.asp" method="post>
<input type="text" name="Username"></input>
</form>

and then Request.Form("Username")

and as for getting people to login, there are login scripts you can use. I can get one for you if you like.

And for a link to submit a form can be done. Use an onclick to a javascript function, then to submit your form.

document.[formname].submit();

I use this all the time, except I use buttons not links.

Sincerely,
Kerry

P.S. if you want working code examples of this, let me know.
 
That might be good. see, the thing is I would have a lot of forms. Its for a student list of up to 40 students...
 
which were you syaing might be good? the javascript or the post method? and did you want code examples of anything?

-Kerry
 
I was saying that the post would be ok. The only thing that I am trying to figure out is how to select a certain vairable and get it to ASP.

I am kind of new with JavaScript. I am guessing that using the OnClick event with the link, I could link it to do the form.submit. How would I use JavaScript to set a form field such as a hidden?

<A href="<img src=" border=0></a>
 
You can use the single form for all of your rcords. Just add a small javascript function like so:
Code:
<script language="Javascript">
function submitValue(aValue){
   document.getElementById("userNameField").value = aValue;
   document.getElementById("userForm").submit();
}
</script>

Then add your form before your records:
Code:
<form method="POST" action="nextPage.asp" id="userForm">
<input type="hidden" name="username" id="userNameField" />
</form>

Then output your links so the onClick event will call the above function and pass it the value for that row:
Code:
Response.Write "<a href=""#"" title=""Some Title"" onClick=""submitValue('" & myRS("field") & "');"">Clik Here!</a>"

Remember when placing your value directly into the onClick function you will need to surround it in single quotes so it will be treated as a string by Javascript. The example above may work out of the box, but you may not need to fiddle with it, not sure. I'm still on cup #1 and I don't always function well before #3 :)

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top