Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to call javascript from html selection option

Posted on 2007-11-16
6
Medium Priority
?
1,895 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 1000 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 1000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

715 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