SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic Select list issue

    Hi

    I'm using javascript to generate a dynamic select list (this page - http://www.insideliquor.com.au/jobs/...job-search.php) . Problem being when category is changed, and position is left as ĎAny positioní no value is sent in the query string for position. ie it should be Ďanypositioní. This is corrected by hitting the back button and submitting again without further change.

    Appreciate any suggestions about how to resolve this problem. Code shown below, Thanks.

    <form name="jobsearch" id="jobsearch" class="generic inline" method="get" action="job-search-results.php">
    <label for="category">Category</label>
    <select id="category" name="category" class="text" onchange="setPositions(this)">
    <option selected value="anycategory">Any category</option>
    <option value="retail">Retail</option>
    <option value="supplier">Supplier</option>
    <option value="hotel">Hotel</option>
    <option value="other">Other</option>
    </select>
    <label for="position">Position</label>
    <select id="position" name="position" class="text">
    <option selected value="anyposition">Any position</option>
    </select>
    <input type="submit" name="jobsearch-submit" value="SEARCH" />
    </form>

    <script type="text/javascript">
    var positiongroup = new Object( )
    positiongroup["retail"] = [{value:"retailassistant", text:"Retail Assistant"},
    {value:"retailsupervisor", text:"Retail Supervisor"},
    {value:"areamanager", text:"Area Manager"}];

    positiongroup["supplier"] = [{value:"1111", text:"1111"},
    {value:"2222", text:"2222"}];

    positiongroup["hotel"] = [{value:"aaaa", text:"aaaa"},
    {value:"bbbb", text:"bbbb"}];

    positiongroup["other"] = [{value:"other-1", text:"other-1"},
    {value:"other-2", text:"other-2"},
    {value:"other-3", text:"other-3"}];

    function setPositions(chooser) {
    var positionChooser = chooser.form.elements["position"];
    // empty previous settings
    positionChooser.options.length = 0;
    // get chosen value to act as index to positionChooser hash table
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = positiongroup[choice];
    // insert default first item
    positionChooser.options[0] = new Option("Any position", "", true, false);
    if (choice != "") {
    // loop through array of the hash table entry, and populate options
    for (var i = 0; i < db.length; i++) {
    positionChooser.options[i + 1] = new Option(db[i].text, db[i].value);
    }
    }
    }
    </script>

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have
    <option selected value="anyposition">Any position</option>

    Try
    <option selected="selected" value="anyposition">Any position</option>
    You have an xhtml DOCTYPE, so all attributes should have values.

    Also, you have
    positionChooser.options[0] = new Option("Any position", "", true, false);

    Should that be
    positionChooser.options[0] = new Option("Any position", "anyposition", true, false);
    I'm assuming the second parameter is for 'value'.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank r51, your 2nd suggestion seemed to fix things up - will do a bit more testing before I'm convinced - but looking good. I looked at the very issue earlier and didn't try it, thinking it couldn't be that easy to fix and wondering why the code was written that way in the first instance (nb I didn't write the function)

    Thanks again.


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
  •