Click to See Complete Forum and Search --> : Do I have to use CGI?


Igwiz
03-06-2003, 07:58 AM
Hi. My web hosting package doesn't allow CGI scripting. So how can I do the following for example:
In a text box, user types in a City name. On Submit, the name is looked up and the approriate link with www.weather.com is opened. This is an example of the kind of thing I want to do. Does this have to be done with a CGI script? I'm very new to this! :( Thanks in advance!

Ig

Tim158
03-06-2003, 12:20 PM
weather.com has their own website tool that does what you want to do, why not use that?

http://oap2.weather.com/oap/index.html?from=servicesindex

If you want to do something a bit different you can use PHP - you don't need to use CGI. PHP is the easiest to learn and most powerfull server-side scripting language (in my opinion).

http://www.php.net

Nedals
03-06-2003, 01:15 PM
In your specific example of www.weather.com you do not necessarily need a server-side script. You will need some javascript that will link to a URL. Something like this....

http://www.weather.com/weather/local/94566?
(on same line)lswe=94566&lwsa=WeatherLocalUndeclared
This will give me the weather in Pleasanton, CA 94566. You will need an array that lists all the cities you want to include and, looking at the URL needed, I would recomend you translate the city to a zip code in your script.

You could instead use a <select...> and a little javascript like this...
<select>
<option value="http://www.weather.com/weather/local/94566?
(on same line)lswe=94566&lwsa=WeatherLocalUndeclared>Pleasanton
<option value="......">City name
etc.
</script>
To check out what the URL needs to be, go to the site, enter a city or zip, and look at the URL in your browser address field.

Not the easiest thing in the world, but if you know javascript you should'nt have too much trouble. If you get into trouble on the way, post whatever code you have and I'm sure someone will help.

Good Luck :)

Igwiz
03-06-2003, 03:10 PM
Great - very helpful thanks. Next question! - How do I call an array? If that is too detailed, can you point me to where I can find out. Thanks!

Nedals
03-06-2003, 06:04 PM
Do you know Javascript? If not, here's a link that Dave Clark (our resident expert) suggests for a Javascript tutorial
http://www.wdvl.com/Authoring/JavaScript/index.html

Not knowing exactly what you are doing makes it a little difficult to suggest the best path. But here a simple script that will sort of work.

<html><head><title>Untitled</title>
<script type="text/javascript">
<!--
function change(data) {
location = "http://www.weather.com/weather/local/" + data.options[data.selectedIndex].value;
}
// assumes "http://www.weather.com/weather/local/" is common to all zip codes
//-->
</script>
</head>

<body>
<form>
<select onChange="change(this)">
<option>Select a city
<option value="94566?lswe=94566&lwsa=WeatherLocalUndeclared">Pleasanton
<option value=".......">city2
<option value=".......">city3
</select>
</form>
</body>
</html>