Solved

how to call javascript from html selection option

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now