File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox & Javascript

 
Venkat Babu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Im using struts and I have six check boxes in the form, if 3rd, 4th and 6th check boxes are selected and clicked submit, I need to popup a window. So onsubmit i am calling a javascript. here's the script but it is not working. Can someone help pls.
html:
-----
<form .... onsubmit="validateBusTypes(this.form)">

javascript:
-----------
function validateBusTypes(f)
{

if (!f.busTypes[3].checked && !f.busTypes[4].checked && !f.busTypes[6]checked) {
alert("Message");
}
}
[ April 14, 2007: Message edited by: Venkat Babu ]
 
mohit bahl
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

First thing you need to change is send "this" to the validate.. function instead of this.form. secondly if you are putting 6 checkboxes then the indexes will be same as in arrays starting from 0-5.

do this and and try again.

cheers!
mohit
 
Venkat Babu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per your suggestion I did the changes, but still it is not working. Any ideas?

html
onsubmit="validateBusTypes(this)"

jsp

function validateBusTypes(f)
{
if (f.busTypes[2].checked || f.busTypes[3].checked || f.busTypes[5]checked) {
alert("Message");
}
}
 
kucool
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have had a try like this:
<html:form action="/login" method="post" onsubmit = "submitbustype(this)">
...
<html:checkbox property="bustype" value = "bus1"/>bus1 <html:checkbox property="bustype" value = "bus2"/> bus2
<html:checkbox property="bustype" value = "bus3"/>bus3
.........
<script type="text/javascript">
function submitbustype(f)
{
if (f.bustype[0].checked || f.bustype[1].checked)
{
alert("message");
}
}
</script>
It works correctly!
 
Venkat Babu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I have :

In the form I have busTypes as String[]

<html:form action="process.do" method="POST"
onsubmit="validateBusTypes(this)">

<script language="JavaScript" type="text/javascript">
function validateBusTypes(f)
{
if (f.busTypes[2].checked || f.busTypes[3].checked || f.busTypes[5]checked) {
alert("message");
}
}
</script>


<c:forEach items="${myForm.busTypeOptions}" var="bus">
<tr>
<td></td>
<TD align=right><html:multibox property="busTypes">
<c ut value="${bus.value}"/></html:multibox>
</td>
<td align=left><FONT face=Arial size=2>
<c ut value="${bus.label}"/></FONT>
</td>
</tr>
</c:forEach>


And still not working. Any help. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic