Solved

how to call javascript from html selection option

Posted on 2007-11-16
6
1,890 Views
Last Modified: 2012-08-13
Hi Guys

I have this html select option code below. What I need is to call this javascript function

javascript:loadStatesFirstUI(this.options[this.selectedIndex].value,<c:out value="${formName}

inside this if statement

<c:if test="${country.code eq USACountry}">
      selected="selected"
</c:if>

Would anyone please help me on this

---------------------------------
<select class="logon select" id="<c:out value="WC_AddressEntryForm_FormInput_${prefix}country_1"/>" name="<c:out value="${prefix}country"/>" onload="javascript:loadStatesFirstUI(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"
                              </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
6 Comments
 
LVL 25

Accepted Solution

by:
James Rodgers earned 250 total points
ID: 20301925
teh usual way with a select is with the onChange event

onChange="someFunction()"
or
onChange="someFunction(somevalue)"

also selects don't have an onload event
0
 

Author Comment

by:huzefaq
ID: 20302023
But I need to call this finction only if it goes inside this if statement

<c:if test="${country.code eq USACountry}">
     selected="selected"
</c:if>
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 250 total points
ID: 20302103
I suppose that you mean that the Javascript code should be run when the page loads in the browser, if any of the options was marked as selected.

The JSP code runs when the page is created on the server, so you can't call a Javascript directly from the JSP code. Also, if you output code that would call the Javascript in the condition, it would end up in the middle of the option tag.

If the condition is true, store the value of the option in a variabe, then after the </select> tag, you can check the value of the variable. If it has been set, you output a script tag that contains the Javascript call, and use the variable value as the first parameter in the call.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20548718
Checking back to see if you had any progress?
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20943732
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

623 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