Solved

how to call javascript inside html <select> tags

Posted on 2007-11-19
1
15,247 Views
Last Modified: 2013-11-24
I have a select tag which populates all the countries. What I need is that when United states is selected it executes a javascript which basically populates the states drop down.

I tried putting the code to call teh javascript inside an if statement which is inside of select tags but somehow it puts teh javascript code as one of the values in dropdown. Would you guys know if I am doing something wrong. Also if this is not possible is there a way I can check outside the select tags if United states is selected, if it is than execute the javascript code.

Any help weill be greatly appreciated

----------------

<select class="logon select" id="<c:out value="WC_AddressEntryForm_FormInput_${prefix}country_1"/>" name="<c:out value="${prefix}country"/>" onchange="javascript:loadStatesUI(this.options[this.selectedIndex].value,<c:out value="${formName}"/>, '<c:out value="${prefix}"/>')" >
                  <c:forEach var="country" items="${countryBean.countries}">
                   <c:out value"${country.code}" />
                        <option value="<c:out value="${country.code}"/>"
                              <c:if test="${country.code eq USACountry}">
                                    selected="selected"
                                    <Script>
                                    loadStatesFirstUI(this.options[this.selectedIndex].value,<c:out value="${formName}"/>, '<c:out value="${prefix}"/>')
                                    </Script>
                              </c:if>
                              <c:if test="${country.code eq paramSource.country || country.displayName eq paramSource.country}">
                                    selected="selected"
                              </c:if>
                        ><c:out value="${country.displayName}"/></option>
                  </c:forEach>
            </select>
0
Comment
Question by:huzefaq
1 Comment
 
LVL 11

Accepted Solution

by:
Isisagate earned 500 total points
ID: 20313532
Options never fire events, you need to put the event on the select. Have the select function check the selected option to see id it is the united states, and if it is have it preload, otherwise do nothing.


so maybe something like this..


<select onchange="loadStatesUI(this)">


function loadStatesUI(obj)
{
if(obj.options[obj.options.selectedIndex].value =="United States")
{
//pre load states
}
}



0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now