Solved

how to call javascript from html selection option

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

839 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