Click to See Complete Forum and Search --> : Sending javascript value to page


poab
05-20-2003, 04:28 AM
Hi,

I haven't got much javascript development experience but I think it's probably the best solution to this: What I need to do is pass a variable to a page when clicking on a link. At least I think that's what I want. One major facotr is I'm not allowed beyond 1.0 (unless there is no other solution). What I've got so far is this:

<!--html form--><form name="one" action="myPage.asp" method="post"><input name="oneval" type="hidden" value="open" /></form>
<!--link with javascript--><a href="javascript:document.one.submit">link text</a>

That works spectacularly fine. The link sits in the page the form is invisible, click the link and it passes the hidden input's value to the asp page. All lovely, but with two problems:

1) Everytime a user clicks the link they get the 'Do you want to submit this form unencrypted across the internet" warning pop-up (unless they've disabled it). - which doesn't exactly inspire confidence.
2) Not very elegant is it?

So, anyway to get the same result but bypass the form? Any help much appreciated.

cheers.

Gollum
05-20-2003, 04:40 AM
Well, if there's only one thing to send to the server (or at least a small number) you could try encoding the value in the url...

<form name="one">
<input name="oneval" type="hidden" value="open">
</form>

<!--link with javascript-->
<a href="#" onclick="this.href = 'mywebsite.com?oneval=' + document.one.oneval.value;">link text</a>

what this does is as the user clicks on the link, you copy the value of the hidden into the into the url and set the href. Your ASP page can pick up the value using Request.QueryString("oneval")

poab
05-20-2003, 05:47 AM
Aha! - thanks very much :D

I'm messing about with cookies at the moment but that solution looks to be the fastest for me at the moment

- thanks again.