This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes checkbox & Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "checkbox & Javascript" Watch "checkbox & Javascript" New topic
Author

checkbox & Javascript

Venkat Babu
Ranch Hand

Joined: Jan 12, 2007
Posts: 47
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

Joined: Mar 22, 2006
Posts: 48
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


to err is human, but the company policy doesn't allow it!
Venkat Babu
Ranch Hand

Joined: Jan 12, 2007
Posts: 47
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

Joined: Apr 11, 2007
Posts: 2
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!


learn and learn, just learn!
Venkat Babu
Ranch Hand

Joined: Jan 12, 2007
Posts: 47
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkbox & Javascript
 
Similar Threads
Javascript - Arraylist
check mandatory fields before form is submitted
Problem in request.getParameterValues()
JSP and Javascript
Check Box