Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Some kind of Javascript error

    So I have this web page code, which works (sort of) in Firefox, but only the select works in IE8. To make it work in Firefox the alert(null); has to be there or it won't go to the href given when the myloc == "MySrch". I don't get any feedback errors, which is really confusing.

    SqlStr = "Select DISTINCT Unit From Employee Where PhoneBook = 1 Order by Unit;"
    Set UniNme = Connection.Execute(SqlStr)
    Response.Write "<select id='Unit' onChange='Change(this.id)'>"
    Response.Write "<option value=''>Choose Unit</option><br>"
    Response.Write "<option value='Everyone'>Everyone</option><br>"
    Do While Not UniNme.EOF
    Response.Write "<option value='"&UniNme("Unit")&"'>"&UniNme("Unit")&"</option><br>"
    UniNme.MoveNext
    Loop
    Response.Write "</select><br>"

    Response.Write "Name Search: <input type='text' id='MySrch' onChange='Change(this.id)'>"



    The javascript function is
    function Change(myloc) {
    if (myloc == "Unit") {
    var myindex = document.getElementById(myloc).selectedIndex;
    myvalue = document.getElementsByTagName("option")[myindex].value;
    } else {
    var myvalue = document.getElementById(myloc).value;
    }

    document.cookie = "Temp1="+escape(myloc);
    document.cookie = "Temp2="+escape(myvalue);

    document.location.href="AEmployees.asp?action=Change";

    alert(null);
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    I don't know exactly why it doesn't work, but it's *WAY* overly complex.

    I *REALLY* have to ask WHY you would store the id and value in a cookie and then go to that other AEmployees page instead of just passing the id and value as part of a form posting?

    That implies that when you get to AEmployees.asp you have to use Request.Cookie() to get those values, right?

    AH, well...

    What about simply:
    Code:
    <%
    SqlStr = "Select DISTINCT Unit From Employee Where PhoneBook = 1 Order by Unit;"
    Set UniNme = Connection.Execute(SqlStr)
    Response.Write "<select id='Unit'> "
    Response.Write "<option value=''>Choose Unit</option><br>"
    Response.Write "<option value='Everyone'>Everyone</option><br>"
    Do While Not UniNme.EOF
        Response.Write "<option value='"&UniNme("Unit")&"'>"&UniNme("Unit")&"</option><br>"
        UniNme.MoveNext
    Loop
    Response.Write "</select><br>"
    Response.Write "Name Search: <input type='text' id='MySrch' >"
    %>
    <script type="text/javascript">
    document.getElementById("Unit").onchange = Change;
    document.getElementById("MySrch").onchange = Change;
    
    function Change() 
    {
        if ( this.value == "" ) return; // nothing searched for?
    
        document.cookie = "Temp1="+escape(this.id);
        document.cookie = "Temp2="+escape(this.value);
        document.location.href="AEmployees.asp?action=Change";
    }
    </script>
    Yes, the JS code must go *AFTER* the end of the ASP code.
    Last edited by Old Pedant; 05-08-2013 at 01:16 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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