#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    126
    Rep Power
    13

    Session vars in javascript


    I have the following Javascript to build the data in the drop down menus. My boss wants to use sessions to maintain the vars selected even in these drop down boxes, when a user returns to the search page to perform another search. I have never done this before, and suggestions is great appreciated. Here is the code:

    <script language = "javascript">
    var state=new Array();
    state[0]=new Array("------------------------","0");

    state["AZ"]=new Array("---All Counties---","0"
    ,"Maricopa","Maricopa"
    ,"Pinal","Pinal"
    ,"Pima","Pima"
    ,"Yavapai","Yavapai");

    state["TX"]=new Array("---All Counties---","0"
    ,"Collin", "Collin"
    ,"Dallas", "Dallas"
    ,"Denton", "Denton"
    ,"Ellis", "Ellis"
    ,"Johnson", "Johnson"
    ,"Kaufman", "Kaufman"
    ,"Tarrant", "Tarrant"
    ,"Wise", "Wise");

    state["VA"]=new Array("---All Counties---","0"
    ,"Loudoun", "Loudoun"
    ,"Fairfax", "Fairfax"
    ,"Prince William", "Prince William"
    ,"Stafford", "Stafford");

    var county=new Array();
    county[0]=new Array("------------------------","0");

    county["Maricopa"]=new Array("---All Regions---","0"
    ,"Northeast","Northeast"
    ,"Northwest","Northwest"
    ,"Southeast","Southeast"
    ,"Southwest","Southwest");

    county[2]=new Array("Not Applicable ","0");
    //-- End of Arrays

    //Function to fill County List from our selected State.
    function fillLists(objClassSelect,objListSelect,strListArray) {
    //Declare our variables.
    var intIndex, intValue, strArray, intCounter, intOne, intTwo, intTotal;

    //Get our index of our selected item and retrieve its value.
    intIndex = objClassSelect.selectedIndex;
    intValue = objClassSelect.options[intIndex].value;

    //Set our array to proper main array elements.
    strArray = strListArray[intValue];

    //Clear all entries in our List Select box.
    objListSelect.options.length = 0;

    //Calcualte the total number of our elements which is half since we use two at a time.
    intTotal = strArray.length / 2;

    //Loop through our array and populate our List select box.
    for(intCounter=0;intCounter<intTotal;intCounter++) {
    //Calculate our array elements.
    intOne = intCounter * 2;
    intTwo = intOne + 1;

    //Add a new option and populate with our array data.
    objListSelect.options[intCounter] = new Option;
    objListSelect.options[intCounter].text = strArray[intOne];
    objListSelect.options[intCounter].value = strArray[intTwo];
    }

    //Make sure our first item in List select box is selected.
    objListSelect.selectedIndex = 0;

    //If State box is empty, then unselect the submarket box too
    if (intValue == 0) {
    document.form1.elements['SubMarket'].options.length = 0;
    document.form1.elements['SubMarket'].options[0] = new Option;
    document.form1.elements['SubMarket'].options[0].text = "------------------------";
    document.form1.elements['SubMarket'].options[0].value = "0";
    }

    }

    //Function to fill Submarket List from our selected County.
    function FillSecondList(objClassSelect,objListSelect,strListArray) {
    //Declare our variables.
    var intIndex, intValue, strArray, intCounter, intOne, intTwo, intTotal;

    //Get our index of our selected item and retrieve its value.
    intIndex = objClassSelect.selectedIndex;
    intValue = objClassSelect.options[intIndex].value;

    if (intValue != "Maricopa") {
    intValue = 2;
    }
    //Set our array to proper main array elements.
    strArray = strListArray[intValue];

    //Clear all entries in our List Select box.
    objListSelect.options.length = 0;

    //Calcualte the total number of our elements which is half since we use two at a time.
    intTotal = strArray.length / 2;

    //Loop through our array and populate our List select box.
    for(intCounter=0;intCounter<intTotal;intCounter++) {
    //Calculate our array elements.
    intOne = intCounter * 2;
    intTwo = intOne + 1;

    //Add a new option and populate with our array data.
    objListSelect.options[intCounter] = new Option;
    objListSelect.options[intCounter].text = strArray[intOne];
    objListSelect.options[intCounter].value = strArray[intTwo];
    }

    //Make sure our first item in List select box is selected.
    objListSelect.selectedIndex = 0;
    }

    // Begin Popup function
    function NewWindow(mypage, myname, w, h, scroll) {
    var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    }
    // End -->

    </script>
    <script language="javascript">
    function checkField(f) {
    var targetLen = (navigator.appName == "Netscape")? 1 : 2;
    if (f.month.value.length == targetLen) {
    f.day.focus();
    }
    if (f.day.value.length == targetLen) {
    f.year.focus();
    }
    }
    function checkField2(f) {
    var targetLen = (navigator.appName == "Netscape")? 1 : 2;
    if (f.month1.value.length == targetLen) {
    f.day1.focus();
    }
    if (f.day1.value.length == targetLen) {
    f.year1.focus();
    }
    }
    </script>
    Scott Orton
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Posts
    790
    Rep Power
    15
    scoorton,

    This is the PHP forum. You'd probably have better luck getting an answer to your javascript question in the javascript forum.

IMN logo majestic logo threadwatch logo seochat tools logo