Solved

how to call javascript from html selection option

Posted on 2007-11-16
6
1,880 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
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

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 discusses four methods for overlaying images in a container on a web page
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 Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

763 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