• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

html select onchange

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to call a javascript function using html select onchange in struts?
eg;
<html:html>
<head>
<script>
function fun()
{
var id=document.getElementById("category").value
if (id != 0)
{
document.form.id.action="/action.do"
}

}</script>
</head>
<body>
<html:from action="/set.do" >
<html:select property="name" onchange="javascript:func()"/>
</html:form>
</body>
</html:html>
I am using Struts 1.2.9 so I cant put the name attribute in form.Pliz help me.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using this

document.forms[0].action="/action.do"

if you have multiple forms on your web page you can go through them so if you have two forms on your page you can access th first one like above and the second form would just be using 1 instead of 0.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In struts, the name of the form is always the name of the ActionForm bean to which the action is associated. Example:

<action name="myForm" path="/myAction" type="com.mycompany.MyAction" />

In the following form:

<html:form action="/myAction" />

The name of the form will be "myForm" and you can use it in any JavaScript function.

Hint: When writing JavaScript for a Struts JSP, remember it's the raw HTML generated by the Struts tags that is being used by JavaScript, and not the Struts tags themselves. If you ever have any doubt about what the generated HTML looks like for a given page, just use your browser's view source function to see it.
 
Ingoba Ningthoujam
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. but it is not working.My code is
function fun1(id) { document.forms[0].action="/web/Subcategory1.do?sid="+id return true; }

<td width="278"> <html-el:select property="category" value="" onchange="javascript:func1(this.value)"> <html-el ption value="select">Select Category</html-el ption> <logic:iterate id="id1" name="category" scope="session"> <html-el ption value="${id1}"><bean:write name="id1" property="value" /></html-el ption> </logic:iterate> </html-el:select> </td>

When select the option javascript error is highlighted.Please help.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, when writing JavaScript, you need to set your browser so that it shows detail on all JavaScript errors. The setting is different for the various browsers, but look for it - you'll find it. Then tell us the specific JavaScript error you're getting.

Here's one error I've spotted: This statement:

needs a ";" before "return true".
 
Let's go to the waterfront with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic