Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Dynamic Link Construction JavaScript

So I have a page that has an input text field on it. When I click a button I want the browser to redirect me to a page that has the value fo the text field as a parameter.

For example, if the input text field has 'star' in it, I want the browser to redirect me to page 'http://www.domain.com/a.aspx?id=star'

What javascript code can I use to do this? I want to generate this link dynamically and thus I am thinking of using javascript.

0
simsingh
Asked:
simsingh
  • 4
  • 3
  • 3
  • +1
1 Solution
 
viola123Commented:
<HTML>
      <HEAD>
            <title></title>
            <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <script language=javascript>
            function test(){
                  var val=document.getElementById("Text1");
                  window.location.href="test.aspx?value="+val;
            }
            </script>
      </HEAD>
      <body>
            <INPUT id="Text1" type="text" name="Text1">
            <INPUT id="Button1" type="button" value="GO" name="Button1" onclick="test()">
      </body>
</HTML>


/////////////////// in your aspx file ///////////////////////////////////
            private void Page_Load(object sender, System.EventArgs e)
            {
                  TextBox1.Text = Request.Params["value"];
            }
0
 
viola123Commented:
sorry, it should be:

<HTML>
      <HEAD>
            <title></title>
            <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <script language=javascript>
            function test(){
                  var val=document.getElementById("Text1").value;
                  window.location.href="test.aspx?value="+val;
            }
            </script>
      </HEAD>
      <body>
            <INPUT id="Text1" type="text" name="Text1">
            <INPUT id="Button1" type="button" value="GO" name="Button1" onclick="test()">
      </body>
</HTML>
0
 
StormyWatersCommented:
You don't need javascript.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Q_21355350</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<form name="myform" method="get" action="a.aspx">
<input type="text" name="id" value="star"/>
<input type="submit" value="Go!" name="sbmt"/>
</form>
</body>
</html>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
StormyWatersCommented:
method="get" passes the form values as get parameters. The action of the form is the page you want to go to. the name is the "id" part of "id=whatever" and whatever is typed in will be the "whatever"
0
 
viola123Commented:
the first HTML page will append the value of the textfield to your url.

then the html page direct the user to
test.aspx?value=VALUE IN TEXT FIELD

the aspx file request the querystring from code behind and display it in another text box

wish it help

regards,
viola
0
 
ZvonkoSystems architectCommented:
My version:
<form>
<input type=text name="myField">
<input type=button value="Go" onClick="self.location='http://www.domain.com/a.aspx?id='+this.form.myField.value;">
</form>

0
 
StormyWatersCommented:
Sorry, should've explained why you don't need javascript, in case it isn't self-evident.

The ability to pass user-input in a URL is built into every browser in the way I've outlined. It will automatically create the URL of the format you want.
0
 
ZvonkoSystems architectCommented:
I hope you do not assume you have to explain it to me ;-)
0
 
GwynforWebCommented:
try this

<form action="http://www.domain.com/a.aspx">
 <input name="id">
 <input type="submit">
</form>
0
 
GwynforWebCommented:
or

<form action="http://www.domain.com/a.aspx">
 <input name="id">
 <input type="submit" value="redirect">
</form>

0
 
StormyWatersCommented:
No, not you Zvonko, the asker. :)
0
 
GwynforWebCommented:
I can explain mine to you if you wish Zvonko. :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now