Solved

how to call javascript inside html <select> tags

Posted on 2007-11-19
1
15,297 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

856 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