PDA

View Full Version : Multiple Redirections on a Submit Button (with Text Field)?



Unwind23
02-05-2008, 04:33 PM
Basically, what I'm trying to do seems very simple, but I can't seem to figure out how to do it.

I have a text field and corresponding submit button at the top of my webpage. I have five keywords that users could possibly enter into the text field, and depending on which one the user enters, the submit button should direct them to one of the five corresponding pages. It's like a search function but much, much smaller and simpler, I think.

Is there a way to do this? Any help is appreciated! Thank you!

jscheuer1
02-05-2008, 05:00 PM
Having:


five keywords that users could possibly enter into the text field

is rather a bad idea to begin with. There are virtually an infinite number of words and word-like strings that could be entered. This concept seems more aptly suited to a select element, or perhaps to 5 radio buttons.

To really be of much help though, we would need to see the code involved, preferably via a link to the page on your site that you are having the problem with.

Please post a link to the page on your site that contains the problematic code so we can check it out.

Unwind23
02-05-2008, 05:07 PM
Having:



is rather a bad idea to begin with. There are virtually an infinite number of words and word-like strings that could be entered. This concept seems more aptly suited to a select element, or perhaps to 5 radio buttons.

To really be of much help though, we would need to see the code involved, preferably via a link to the page on your site that you are having the problem with.

Please post a link to the page on your site that contains the problematic code so we can check it out.
The site isn't nearly done yet...I haven't even implemented the code into the page, I was just compiling different features that I'd insert into the code afterward. I understand it isn't the best idea, but there really are a limited amount of keywords they could enter. Is this task even possible (bad of an idea as it may be), or no?

Edit: Also, to compensate for any strange/erroneous keywords, could I add a function where any non-specified keyword (other than the main five) would just redirect to a sixth page?

jscheuer1
02-05-2008, 06:00 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function kWord(f){
switch(f.elements['kword'].value.toLowerCase()){
case 'google':
window.location.href='http://www.google.com';
break;
case 'yahoo':
window.location.href='http://www.yahoo.com';
break;
case 'msn':
window.location.href='http://www.msn.com';
break;
case 'dd':
window.location.href='http://www.dynamicdrive.com';
break;
case 'ask':
window.location.href='http://www.ask.com';
break;
default: window.location.href='http://www.loisimages.com';
}
}
</script>
</head>
<body>
<form action="javascript:void();" onsubmit="kWord(this);return false;">
<input type="submit" value="Go!">
<input type="text" name="kword">
</form>
</body>
</html>

BLiZZaRD
02-05-2008, 06:03 PM
If this must be done, going along with John, I would opt for the radio button/check box option, give them the 5 to choose from, thus eroding any errors from possible input.

Unwind23
02-05-2008, 06:08 PM
You guys are awesome.

THANK YOU!!

Unwind23
02-08-2008, 09:11 PM
I'd hate to bug you guys again since you've been so incredibly helpful to me so far, but I hit a small snag...

One of the keywords I'd like them to enter features a quotation mark in it ( " ). However, the function doesn't seem to recognize the quotations and just sends those search queries to the default results page. Is there a way to have the quotation marks recognized?

(The search term is 32" Waist)

Thank you so much again for your help!

thetestingsite
02-08-2008, 09:18 PM
Simply add something like the following for whichever keyword you want (the highlighted part is the one with the quotation mark in it).



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function kWord(f){
switch(f.elements['kword'].value.toLowerCase()){
case 'google':
window.location.href='http://www.google.com';
break;
case 'yahoo':
window.location.href='http://www.yahoo.com';
break;
case '"testing"':
window.location.href='http://www.thetestingsite.net';
break;
case 'msn':
window.location.href='http://www.msn.com';
break;
case 'dd':
window.location.href='http://www.dynamicdrive.com';
break;
case 'ask':
window.location.href='http://www.ask.com';
break;
default: window.location.href='http://www.loisimages.com';
}
}
</script>
</head>
<body>
<form action="javascript:void();" onsubmit="kWord(this);return false;">
<input type="submit" value="Go!">
<input type="text" name="kword">
</form>
</body>
</html>


Hope this helps.

Unwind23
02-08-2008, 09:48 PM
I feel stupid -- I noticed that I was using an inch symbol in the code rather than quotations. I swapped the characters and now it works perfectly. Sorry about that, thanks for the help!!