Welcome to WebmasterWorld Guest from 54.158.52.166

Forum Moderators: open

Message Too Old, No Replies

HTML Form Field Site Redirect

     
10:57 pm on Oct 23, 2008 (gmt 0)

New User

5+ Year Member

joined:Oct 23, 2008
posts: 3
votes: 0


I am looking for a VERY SIMPLE, yet cross browser supported, code that will allow visitors to my site to enter text into a form field and upon submission be redirected to the directory name they entered.

Let me explain.

One field form with SUBMIT button.
The visitor is at www.example.com
They enter "text" into the form field and click SUBMIT.
The code redirects them to www.example.com/text

Thank you for your help.

[edited by: tedster at 11:07 pm (utc) on Oct. 23, 2008]
[edit reason] switch to example.com - it can never be owned [/edit]

11:48 pm on Oct 23, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12548
votes: 2


Welcome to WebmasterWorld, tkimage.

Quite simple, really. You create the form with a method attribute that reads the text entered and either redirects them to the new directory index page or returns a message that an invalid directory has been entered. Which server-side language are you using?

3:28 am on Oct 24, 2008 (gmt 0)

New User

5+ Year Member

joined:Oct 23, 2008
posts: 3
votes: 0


I have access to the following: CGI, SSI, PHP 5, PERL 5, Apache ASP

Thank you for your assistance.

1:20 pm on Oct 24, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:July 5, 2005
posts:352
votes: 0


Or maybe a simple JavaScript would be sufficient?
<form action="" method="">
<fieldset>
<legend>The form</legend>
<input type="text" id="addy">
<input type="button" id="theButton" value="Go!">
</fieldset>
</form>

<script type="text/javascript">
document.getElementById('theButton').onclick = function(){
document.location.href=document.getElementById('addy').value;
}
</script>

4:52 am on Oct 26, 2008 (gmt 0)

New User

5+ Year Member

joined:Oct 23, 2008
posts: 3
votes: 0


Thank you "Trace" the JavaScript works great. I tested it in IE, FF, and Safari.

However, when I try to replace type="button" with type="image" and the neccessary info to get my image to be viewed, it quits working? Why?

Also, when you hit the "Enter/Return" on the keyboard, it doesn't work, but if you click the button with the mouse it does. Why?

Your help is greatly appreciated.

10:56 pm on Oct 26, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 18, 2004
posts:61
votes: 0


tkimage,

type="image" will trigger the form action so if you want to use onclick you should use type="button". if you need a custom image just use the <img> tag.

enter/return on a form field will also trigger the form action, if you put the focus (tab to) the button then press enter/return it should act as you expect.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members