OnChange Filter To First Value Request
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: OnChange Filter To First Value Request

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Arrow OnChange Filter To First Value Request

    Hello
    I am running a php & java script that when searching for a property, it uses the onchange feature for three fields regarding the location of the property.
    for example: Country, Parish, Area

    When you choose a country, you then choose a Parish(which correspons to the country) and then an Area (that corresponds to the Parish)

    Thing is, I am only using one country and would like the script to automatically show/filter to that country rather than 'Any'. For example I would want the Country field to show United Kingdom as a default.

    Here is a link to a screenshot of how it looks now:
    http://tinypic.com/view.php?pic=vncsw5&s=5


    And here is a segment of the code from the php file that it uses to change the fields

    Code:
     <form action="<?php echo URL ?>/search.php" method="POST" name="form">
    
    
    
    
    <?php echo $lang['WHERE']; ?>:</h2>
    
    <?php echo $lang['Location1'] ?> <br>
    <select name="location1" class="span3" onchange="update(this, locations);">
    <option></option>
    <option></option>
    <option></option>
    </select>
    <br>
    <br>
    <?php echo $lang['Location2'] ?> <br>
    <select name="location2" class="span3" onChange="update(this, locations);">
    <option></option>
    <option></option>
    <option></option>
    </select>
    <br>
    <br>
    <?php echo $lang['Location3'] ?> <br>
    <select name="location3" class="span3">
    <option></option>
    <option></option>
    <option></option>
    </select>
    
    <input type="hidden" name="form" value="1">
    <input type="hidden" name="loc" value="">
    
    <br><br>
    What i want is to filter to first value(United Kingdom) by default in the dropdown (location1)
    I checked on the net and it was suggested to have another javascript running after the listbox using selectedIndex=1 but I'm not sure how to implement it.

    Any help would be greatly appreciated
    Thanks
    Last edited by PeejAvery; January 11th, 2009 at 07:23 PM.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,860

    Re: OnChange Filter To First Value Request

    You could use selectedIndex. It is very simple. The index corresponds to the <option> that you want to be preselected. However, it is not the best solution. You want to use the selected attribute in the <option> tag.

    Code:
    <select name="foo">
    <option>bar 1</option>
    <option>bar 2</option>
    <option selected="selected">bar 3</option>
    </select>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2009
    Posts
    2

    Re: OnChange Filter To First Value Request

    THanks PJ
    Its still not having the first value from the database being shown first tho

    My focus is on this part of the code

    <?php echo $lang['WHERE']; ?>:</h2>

    <?php echo $lang['Location1'] ?> <br>
    <select name="location1" class="span3" onchange="update(this, locations);">
    <option></option>
    <option></option>
    <option></option>
    </select>
    <br>

    See the options come from a database and are not put in manually
    I only just saw there is a java forum. SHould I post this query in there? Just checking
    Thanks again

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center