?
Solved

Dynamic Link Construction JavaScript

Posted on 2005-03-17
12
Medium Priority
?
229 Views
Last Modified: 2008-03-06
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
Comment
Question by:simsingh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 6

Expert Comment

by:viola123
ID: 13570579
<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
 
LVL 6

Expert Comment

by:viola123
ID: 13570586
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
 
LVL 13

Accepted Solution

by:
StormyWaters earned 2000 total points
ID: 13570595
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 13

Expert Comment

by:StormyWaters
ID: 13570608
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
 
LVL 6

Expert Comment

by:viola123
ID: 13570615
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 13570631
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
 
LVL 13

Expert Comment

by:StormyWaters
ID: 13570636
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 13570649
I hope you do not assume you have to explain it to me ;-)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13570668
try this

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

Expert Comment

by:GwynforWeb
ID: 13570679
or

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

0
 
LVL 13

Expert Comment

by:StormyWaters
ID: 13570713
No, not you Zvonko, the asker. :)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13570731
I can explain mine to you if you wish Zvonko. :-)
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question