?
Solved

how to call javascript inside html <select> tags

Posted on 2007-11-19
1
Medium Priority
?
15,348 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 2000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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…
Suggested Courses

752 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