OnChange Filter to first Value Request

5 pts.
Tags:
JavaScript
onChange Event
PHP
Web development
Hello I am running a script that when searching for a property, it uses the onchange feature for three fields regarding the location of the property. for example: Country, State, City When you choose a country, you then choose a state(which correspons to the country) and then a city(that corresponds to the state) 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 States as a default. Here is a link to a screenshot of how it looks: http://tinypic.com/view.php?pic=vncsw5&s=5 And here is the code from the php file that it uses to change the fields ------------------------ <?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 with first value 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

Answer Wiki

Thanks. We'll let you know when a new response is added.

The reason there is an “Any” option in the first place is probably trigger the onchange event needed by the other dropdowns. What I would do is get rid of the “Any” option so that the select box has only a single option that is already selected to your country, and then move the onchange handler to an onload handler, e.g.

<select name=”location1″> <– since there is only one option you can get rid of the onload handler
<option>United State</option>
</select>

on the body tag add onload=”update(document.formXXX.location1, locations)”

If the option will always be the US, why even give the user the ability to select “Any” and undo the values of the other select boxes.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following