Re: JavaScript

by Thomas James Allen <tjallen(at)pipeline.com>

 Date:  Sat, 04 Sep 1999 00:26:56 -0400
 To:  Kassianna(at)WiccanWeb.Net
 Cc:  hwg-basics(at)hwg.org
  todo: View Thread, Original
At 09:38 AM 8/25/99 -0700, you wrote:
...
>I'm trying to do a form questionnaire that will ask people
>where they heard of our site, what their primary interest is (information
>or purchase) and than have them give me their location (California, Other
>U.S. State, or International) and then, depending on which location they
>give, I want to take them to separate pages

<snip>

>Cheers,
>Kass
------------------------
Kass,
The easiest way to do what you're asking is to make a selection box
(a pull-down selection list) which has the name of every state.
This keeps them from writing their state in different ways, ie
CA, Ca, ca, calif, california, etc, etc, etc.

Then make the values of each selection option = the name of the page
that you will send them to, without the ".html" like this:

<form name="fred">
<select name="state">
<option value="al">Alabama
<option value="ak">Alaska
<option value="ar">Arkansas
.
. other states here
.
<option value="wi">Wisconsin
<option value="wy">Wyoming
<option value="int">International
</select> 
<input type="button" value="submit" onclick="grabInfo()">
</form>

Instead of a submit button, you put an input button with an "onclick"
that sends them to a javascript function, like this:

<input type="button" value="submit" onclick="grabInfo()">

and grabInfo() is a javascript in the head section of your page, like this:

<script language="JavaScript">
<!-- hide script
//function to grab state from form and send viewer to new page
function grabInfo(){
var n=document.fred.state.selectedIndex;
var s=document.fred.state.options[n].value;
location.replace(s + ".html");
}
//end of hiding -->
</script>

In this javascript, n is the state they picked (number n in the list)
s is the value of that number, as you set it (al, ak, ar, wy, etc),
fred is the name I gave to the form, and state is the name I gave
to the selection box. The last line takes s, adds ".html" to it,
and sends them on their way!

That should do it, you can modify it as needed.
Sorry it took me a week to answer, 
maybe someone else already helped you.

Hope this helps,
jimmy

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA