Solved

how to call javascript inside html <select> tags

Posted on 2007-11-19
1
15,333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

729 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