Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

checkbox & Javascript

 
Ranch Hand
Posts: 47
  • 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 ]
 
Ranch Hand
Posts: 48
  • 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
  • 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");
}
}
 
Greenhorn
Posts: 2
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic