Passing value of a text box in a href tag

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

In a form I have a text called myText as input and need to pass its value to
the next page (mySecond.asp)
The following works fine and my next page I get the value of myText=test:
<a href="mySecond.asp?MyText=test">click here</a>
But, I need to pass document.myform.myText.value instead of test value.
I have problem with the syntax. I'm sure I need to use javascript, but how?
Thanks in advance,

Roy
 
You could use a normal HTML FORM (anyone remember those? :) )

<form method="GET" action="mySecond.asp">
<input type="text" name="MyText">
<input type="submit" value="Go">
</form>

The alternative would be to do a normal asp.net postback, read the value
then Response.Redirect to the new URL.
 
Hi Roy,

<input type="text" id="myText"/>
<a href="javascript:RedirectToSecondPage()">click here</a>

<script type="text/javascript">
function RedirectToSecondPage()
{
var input = document.getElementById('myText');
var value = input ? input.value : 'defaultText';

window.location.href = 'mySecond.asp?MyText=' + escape(value);
}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top