Solved

input box value to change URL or href link in html

Posted on 2010-11-11
14
731 Views
Last Modified: 2012-06-27
Dear Experts,

I would like to ask html question about user input  number in input box to
link href or URL according to the input number change in html. How to change URL from input box with enter keys
and with  submit button. Hope you can provide two method simple code.
Frr example, if I input product no=666789 , the href link will go to web search
http://www.mywbsite.com/666789.htm

Please advise

Duncan

*********

< input product number and press enter key  to change href link

<html>

<body>

<form method="get" action="http:/www.mywebsite.com/#myvariable#.htm">

ProductNO: <input type="text" name="myvariable" value="">

</form>

</body>

</html>

************************************************

<-Click input product no and click submit button to change href

<html>

<body>

<form method="get" action="http:/www.mywebsite.com/#myvariable#.htm">

ProductNO: <input type="text" name="myvariable" value="">

<input type="submit" value="Submit">

</form>

</body>

</html>

Open in new window

0
Comment
Question by:duncanb7
  • 7
  • 3
  • 2
  • +1
14 Comments
 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 25 total points
ID: 34113393
maybe a little js will suffice.

see if this helps
<html>

<head>



<script language="Javascript">

<!--



function passtourl(){



var frm = document.FormName



var t1value = frm.myvariable.value



frm.action = "http:/www.mywebsite.com?myvariable=" + value

frm.submit()



}



//-->

</script>



</head>



<body>



<form name="FormName" method="Post">

<input type="text" name="myvariable" ><br>

</form>

...

<p><a href="javascript: passtourl()">click to pass</a></p>



</body>



</html>

Open in new window

0
 
LVL 13

Author Comment

by:duncanb7
ID: 34113526
Is it okay for enter key only without button click
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34113549
I try it and no response for enter key or click, the url is same as before
0
 
LVL 16

Expert Comment

by:jmatix
ID: 34113774
Try this:
*********

< input product number and press enter key  to change href link

<html>

<head>

<script>

function formSubmit(frm)

{

  frm.action = frm.action.replace(/#[^#]+#/, frm.myvariable.value);

}

</script>

</head>



<body>

<form method="get" action="http:/www.mywebsite.com/#myvariable#.htm">

ProductNO: <input type="text" name="myvariable" value="">

</form>

</body>

</html>

************************************************

<-Click input product no and click submit button to change href

<html>

<body>

<form method="get" action="http:/www.mywebsite.com/#myvariable#.htm" onsubmit="return formSubmit(this)">

ProductNO: <input type="text" name="myvariable" value="">

<input type="submit" value="Submit">

</form>

</body>

</html>

Open in new window

0
 
LVL 16

Assisted Solution

by:jmatix
jmatix earned 25 total points
ID: 34113807
Sorry duplicate <html> tags. Try this:
<html>

<head>

<script>

function formSubmit(frm)

{

  frm.action = frm.action.replace(/#[^#]+#/, frm.myvariable.value);

}

</script>

</head>



<body>

<form method="get" action="http:/www.mywebsite.com/#myvariable#.htm" onsubmit="return formSubmit(this)">

ProductNO: <input type="text" name="myvariable" value="">

<input type="submit" value="Submit">

</form>

</body>

</html>

Open in new window

0
 
LVL 13

Author Comment

by:duncanb7
ID: 34113877
it is same as before URL is no change, be reminded I also need both way  of entery keys to submit and button click submit
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34113921
sorry, some silly bug
<html>

<head>



<script language="Javascript">

<!--



function passtourl(){



var frm = document.FormName



var valuea = frm.myvariable.value



frm.action = "mywebsite.com?myvariable=" + valuea

frm.submit()



}



//-->

</script>



</head>



<body>



<form name="FormName" method="Post">

<input type="text" name="myvariable" ><br>

</form>

<p><a href="javascript: passtourl()">click to pass</a></p>



</body>



</html>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34113946
Try this with button
<html>

<head>



<script language="Javascript">

<!--



function passtourl(){



var frm = document.FormName



var valuea = frm.myvariable.value



frm.action = "mywebsite.com?myvariable=" + valuea

frm.submit()



}



//-->

</script>



</head>



<body>



<form name="FormName" method="Post">

<input type="text" name="myvariable" ><br>

</form>

<p><input type="submit" name="submit" Onclick="passtourl()" value="Submit">



</body>



</html>

Open in new window

0
 
LVL 13

Author Comment

by:duncanb7
ID: 34114010
where ie *.htm" you put
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34114040
frm.action = "mywebsite.com?myvariable=" + valuea

Is it typing mistake valuea, it should be no "a", right
0
 
LVL 13

Author Comment

by:duncanb7
ID: 34114209
it is same and just a little change but  why it will have "?=" and could it delete it

www.mywbeiste.com/?=123
0
 
LVL 14

Accepted Solution

by:
sam2912 earned 200 total points
ID: 34114499

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Change URL via Textbox</title>
</head>
<body>
<form method="post" onsubmit="window.location='http://www.mywebsite.com/'+this.prodNum.value+'.htm';return false;">
	<input type="text" name="prodNum" />
	<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Open in new window

0
 
LVL 13

Author Closing Comment

by:duncanb7
ID: 34114632
THanks,  sam2912, it works finally
with your code.

Thanks for all of you to reply this thread
0
 
LVL 14

Expert Comment

by:sam2912
ID: 34114780
Thanks for the points, and have a nice day!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with a CSS in a page 2 27
html input type 3 23
geting geocode of a user with using Google maps api 8 19
how to avoid redundand ajax calls 5 10
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now