SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Portland, OR
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JScript not being read??

    I am having a hard time with this script-- NS 4.75 and IE 5.5 are browsers i am using, but they seem to be ignoring my script. i tried copying a script from a tutorial just to see if i could get it to work on my server but it didn't. any suggestions? here is my script, if that helps.
    TIA,
    s.

    <HTML>
    <HEAD>

    <TITLE>Gaging Station Inventory Database</TITLE>

    <SCRIPT LANGUAGE="JavaScript" type=text/javascript>
    <!--
    //this function sets document.cookie equal to "name:$FORM{$name}" and parses
    //it for cookie storage
    function cookie() {
    var the_name = document.identify.options.value;
    var the_cookie = "sadies_javascript=" + escape("name:" + the_name);
    document.cookie = the_cookie;
    {
    //this is an alert box to check whether the script works.
    alert(document.cookie);
    }
    }

    //this function ensures that a station is selected
    function validate() {
    if (document.identify.options[0].selected) {
    alert('Please select a gaging station');
    return false;
    } else return true;
    }
    //-->

    </SCRIPT>
    </HEAD>

    <BODY bgcolor="#cccc99" text="#003300" vlink="#dd9911" link="#0033aa">
    <BR>
    <BR>
    <H3 ALIGN='CENTER' text="#dd9911">Gaging Station Inventory Database</H3>
    <H4 ALIGN='CENTER'>Oregon District</H4>


    <H5 ALIGN=CENTER>Please select a gaging station/H5>

    <table align=center>
    <tr><td><IMG SRC="http://oregon.usgs.gov/uo/safety/gagehouse/pictures/swsites.gif" ALT="Site map of Oregon">
    </table>
    <BR>

    <FORM NAME=identify onSubmit="return validate();" ACTION="http://oregon.usgs.gov/cgi-bin/uo/gagehouse/gage_home.pl" method="post">
    <TABLE align=center><TR>
    <TD><SELECT name="name">
    <OPTION value=noselect>--Select One--
    <OPTION value=roosevelt>14306900 Big Cr nr Roosevelt Beach
    <OPTION value=siletz>14305500 Siletz nr Siletz, OR
    <OPTION value=beaver>14303600 Nestucca R nr Beaver, OR
    <OPTION value=fairdale2>14302900 Nestucca R nr Fairdale
    <OPTION value=tillamook>14301500 Wilson R nr Tillamook
    <OPTION value=foss>14301000 Nehalem R nr Foss, OR
    <OPTION value=ariel>14220500 Lewis R @ Ariel, WA
    <OPTION value=cougar>14219800 Speelyai Cr nr Cougar, WA
    <OPTION value=estacada>14210000 Clackamas R @ Estacada, OR
    <OPTION value=fish>14209700 Fish Cr
    <OPTION value=lynx>14209500 Clackamas R av 3 Lynx Cr
    <OPTION value=power>14209000 Oakgrove Fork abv Power Plant intake
    <OPTION value=camp>14208700 Oakgrove Fork nr Govt Camp
    <OPTION value=wilhoit>14198500 Molalla R ne Wilhoit, OR
    <OPTION value=fairdale>14194300 N Yamhill R nr Fairdale
    <OPTION value=jefferson>14189000 Santiam R @ Jefferson, OR
    <OPTION value=mehama>14183000 N Santiam R @ Mehama
    <OPTION value=lilmehama>14182500 Little N Santiam R @ Mehama
    <OPTION value=niagara>14181500 N Santiam R nr Niagara
    <OPTION value=humbug>14178700 E Humbug Cr
    <OPTION value=boulder>14178000 N Santiam R nr blw Boulder Cr
    <OPTION value=monroe>14170000 Long Tom R @ Monroe
    <OPTION value=alvadore>14169000 Long Tom R nr Alvadore
    <OPTION value=nots>14166500 Long Tom R @ Nots
    <OPTION value=jasper>14152000 M F Willamett R @ Jasper, OR
    <OPTION value=fall>14151000 Fall Cr blw Wineberry Cr nr Fall Cr, OR
    <OPTION value=lowell>14150300 Fall Cr nr Lowell, OR
    <OPTION value=dexter>14150000 M F Willamett R nr Dexter, OR
    <OPTION value=oakridge3>14148000 M F Willamette R blw N F nr Oakridge, OR
    <OPTION value=oakridge2>14147500 N F of Willamette R nr Oakridge, OR
    <OPTION value=salmon>14146500 Salmon Cr nr Oakridge, OR
    <OPTION value=salt>14155000 M F Willamette R abv Salt Cr nr Oakridge, OR
    <OPTION value=oakridge>14144800 M F Willamette R nr Oakridge, OR
    <OPTION value=lilsandy>14141500 Little Sandy R nr Bull Run, OR
    <OPTION value=bull2>14140000 Bull Run, nr Bull Run, OR
    <OPTION value=bull>14139800 S F Bull Run nr Bull Run, OR
    <OPTION value=brightwood>14138870 Fir Cr nr Brightwood, OR
    <OPTION value=mult>14138850 Bull Run R nr Multnomah Falls, OR
    <OPTION value=hood>14120000 Hood R @ Tucker Bridge
    <OPTION value=moody>14103000 Deschutes R @ Moody
    <OPTION value=mill>14096300 Mill Cr
    <OPTION value=pasture>14092750 Sitike Cr @ P Pasture
    <OPTION value=grandview>14091500 Metolius R nr Grandview
    <OPTION value=sherman>14090400 Whitewater R nr Camp Sherman
    <OPTION value=crook>14087400 Crooked R nr Culver
    </SELECT>
    </TD>
    <td>
    <INPUT TYPE="SUBMIT" value="go" ;">
    </td></table>
    </FORM>

    <HR>
    <BR>
    To give feedback about this page, send mail to Sadie Morse <A HREF="skmorse@usgs.gov">skmorse@usgs.gov </A>
    <BR><BR>
    <address>
    U.S. Geological Survey<br>
    http://oregon.usgs.gov/uo/safety/safety_page.html<br>

    Last modified Friday - Jul 14, 2000 at 08:52:46 PDT<br>
    <a href="http://www.usgs.gov/privacy.html" target=_parent>Privacy Statement</a> &#183;
    <a href="http://www.usgs.gov/disclaimer.html" target=_parent>Disclaimer</a> &#183;
    <a href="http://www.usgs.gov/foia/" target=_parent>FOIA</a> &#183;
    <a href="http://www.usgs.gov/accessibility.html" target=_parent>Accessibility</a>
    </address>

    <HR>
    <P>
    Copyright &copy; 2001 USGS Revised 22 October 2001<BR>
    <BR>Return to Oregon District <A HREF="http://oregon.usgs.gov" TARGET="_top">homepage </A>
    <BR>
    </BODY>
    </HTML>




  2. #2
    SitePoint Member
    Join Date
    Nov 2001
    Location
    Lexington, KY U.S.A.
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not calling the cookie() function anywhere. I'll listen in on this thread in case that doesn't do it.

    --Jeff

  3. #3
    SitePoint Enthusiast RogueJedi's Avatar
    Join Date
    Oct 2001
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Three problems I noticed:
    1) function cookie() is not being called from anywhere, so the document.cookies value is not getting set.
    2) In function validate() your if-else statement has mismatched curly braces. This is probably just a typo.
    3) In function validate(), your if statement is checking "document.identify.options[0].selected". This does not exist, so you are probably getting an error message similar to "document.identify.options[0].selected is not an object". Change this to "document.identify.name.options[0].selected", and it should work. You do the same thing in function cookie() when you set "var the_name = document.identify.options.value;". But, since the function is not being called this error would not show up immediately.

    Try this in your document's head section:
    Code:
    <SCRIPT LANGUAGE="JavaScript" type=text/javascript> 
    <!-- 
    //this function sets document.cookie equal to "name:$FORM{$name}" and parses 
    //it for cookie storage 
    function cookie() { 
        var the_name = document.identify.name.options.value; 
        var the_cookie = "sadies_javascript=" + escape("name:" + the_name); 
        document.cookie = the_cookie; 
        //this is an alert box to check whether the script works. 
        alert(document.cookie); 
    } 
    
    //this function ensures that a station is selected 
    function validate() { 
        if (document.identify.name.options[0].selected) { 
            alert('Please select a gaging station'); 
            return false; 
        } 
        else {
            cookie();
            return true; 
        }
    } 
    //--> 
    
    </SCRIPT>
    Last edited by RogueJedi; Nov 14, 2001 at 14:32.
    Rob Nolan
    Do or do not, there is no try.

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Portland, OR
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, thanks guys-- it actually works now (almost, anyway). one more question: the value of document.cookie is being set to "sadies_javascript=name%3Anull", regardless of which option is selected. why null?? this confuses me...

  5. #5
    SitePoint Member
    Join Date
    Nov 2001
    Location
    Lexington, KY U.S.A.
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked a little closer at what you're trying to accomplish (duh!). I tried calling the cookie() function from the select tag:

    Code:
    <SELECT name="name" onChange="setCookie()">
    If you're still calling it from the body tag with onLoad, you're looking for the value before the user has selected anything.

    --Jeff

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Portland, OR
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried calling the cookie function in the select tag, but i keep getting a null value...

  7. #7
    SitePoint Member
    Join Date
    Nov 2001
    Location
    Lexington, KY U.S.A.
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, this was working in IE, but not NN. IE picks up whatever option that is set. With NN, you have to loop through the options array to find the one that's selected. This script should work for you . . .

    Code:
    <SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
    //this function sets document.cookie equal to "name:$FORM{$name}" and parses 
    //it for cookie storage
    
    function cookie() { 
    	for (var i=0; i <document.identify.location.length; i++) {
    		if (document.identify.location.options[i].selected==true) {
    			var the_name = document.identify.location.options[i].value;
    		}
    	} 
    	var the_cookie = "sadies_javascript=" + escape("name:" + the_name); 
        document.cookie = the_cookie; 
        //this is an alert box to check whether the script works. 
        alert(document.cookie); 
    } 
    
    //this function ensures that a station is selected 
    function validate() { 
        if (document.identify.location.selected) { 
            alert('Please select a gaging station'); 
            return false; 
        } 
        else {
    	    cookie();
            return true; 
        }
    } 
    //--> 
    
    </SCRIPT>
    --Jeff


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •