...

View Full Version : regarding checkboxes



remish
05-08-2009, 08:27 AM
Hello guys,
Plz if anyone can help me to solve my problem.
I am stuck wid a problem of javascript.
My problem is that i am using checkboxes whose values is comming from database.Its name is same but name is fetching like:
<input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
through this i am getting the values from the database.
Now i have to validate that at least one checkbox should be selected..

So plz anyone help me how i can do that.
If i am giving like this the javascript code:
var services = document.getElementsById( 'chkBankServices' );
if(!(services[0].checked) && !(services[1].checked) && !(services[2].checked) && !(services[3].checked)
&& !(services[4].checked) && !(services[5].checked) && !(services[6].checked) && !(services[7].checked)
&& !(services[8].checked))
{ alert( "Please select at least one service to submit." );
return false;
}

Its not giving any alert message.
Is anything wrong in that.
Plz help me...
Thanks in advance

remish
05-08-2009, 08:40 AM
Plz anyone reply me..its urgent

Philip M
05-08-2009, 12:14 PM
Bumping after only 13 minutes seems rather premature. :( You need to be more patient - this forum is not some sort of public enquiry service with people standing by 24/7 to answer your questions.

Also you have double posted in Javascript Framewoks also. See forum Rule 1.2:

1.2) Do not crosspost - CodingForums.com is divided into various categories. When initiating a thread, always locate the most appropriate category, and post your question only ONCE, in that category. Do not post the same question in multiple categories.

I think it would be a good idea if you had a look at

http://www.catb.org/~esr/faqs/smart-questions.html

Particularly:
Don't flag your question as “Urgent”, even if it is for you.
That's your problem, not ours. Claiming urgency is very likely to be counter-productive: most forum users will simply delete such messages as rude and selfish attempts to elicit immediate and special attention.

In short, you are much more likely to get a response if you show some respect for the forum rules, guidelines and conventions.

remish
05-11-2009, 06:59 AM
Actually Mr philp i have posted it on 8th of may.But till now i didnt get any solution.
Main problem is this, here no one is there to give the solution but everyone is there to give the suggestion.
And if you can give the solution of my question then plz do that because i no well how i have to post and what i have to write.Coz i have posted the query on 8th and till now no response.

remish
05-11-2009, 07:05 AM
Actually mr. philip i have posted my query on 8th of may and till now i didnt recieve the solution.
Main problem is that,here no one to give the solution but everyone to give the suggestion.
So i dont need the suggestion ,i need the solution.
So plz keep your suggestion wid you and if you have the solution of mine query the please give that.I know what i have posted and what i have used.i didnt be selfish.my query is been posted on 8th may and today is 11th may and solution is null.

adios
05-11-2009, 08:57 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>untitled</title>
<script type="text/javascript">

function oneChecked()
{
var box, n = 1;
while (box = document.getElementById('chkBankServices' + n++))
{
if (box.checked)
{
return true;
}
}
alert('Please select at least one service to submit.');
return false;
}

</script>
</head>
<body>
<form id="bankform" onsubmit="return oneChecked()">
<input type="checkbox" id="chkBankServices1" name="bs1">... some service<br />
<input type="checkbox" id="chkBankServices2" name="bs2">... some service<br />
<input type="checkbox" id="chkBankServices3" name="bs3">... some service<br />
<input type="checkbox" id="chkBankServices4" name="bs4">... some service<br /><br />
<input type="submit" />
</body>
</html>

ids must be unique (and, no such thing as document.getElementsById).
Just have your asp give the checkboxes consecutive ids ("chkBankServices1", "chkBankServices2", ....). That'll give the loop something to look for.

remish
05-12-2009, 12:25 PM
thanks mr. adios,
but my problem is i am fetching the data from database like this:
*********Java Script******
var services = document.getElementsById( 'chkBankServices' );

if(!(services[0].checked) && !(services[1].checked) && !(services[2].checked) && !(services[3].checked)
&& !(services[4].checked) && !(services[5].checked) && !(services[6].checked) && !(services[7].checked)
&& !(services[8].checked))
{ alert( "Please select at least one service to submit." );
return false;
}
else{
document.frmCustomerUpdation.cmd.value='btnUpdate';
document.frmCustomerUpdation.submit();
}

**********HTML************


<td><b>Banking Services:</td>
</tr>
<%

//System.out.println("vecResult.size--------"+vecResult.size());
if(vecResult != null)
for (int i = 0; i < vecResult.size(); i++) {
BankService bs = (BankService) vecResult.elementAt(i);
for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
BankService objCustomerService = (BankService) vecUpdateCustomerID.elementAt(j);
//TBD:
if (objCustomerService.getServiceID() == bs.getServiceID()) {
System.out.println(bs.getServiceID() + " "
+ objCustomerService.getServiceID());
%>
<tr>
<td colspan="2"><input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>
</td>
</tr>
<%
break;
}
}
}
boolean blnSelected = false;
if(vecResult != null)
for (int i = 0; i < vecResult.size(); i++) {
BankService bs = (BankService) vecResult.elementAt(i);
for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
BankService objCustomerService = (BankService) vecUpdateCustomerID
.elementAt(j);

if (objCustomerService.getServiceID() == bs.getServiceID()) {
blnSelected = true;
break;
}
}
if (!blnSelected) {
%>
<tr>
<td colspan="2"><input type="checkbox" id="chkBankServices" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
</td>
</tr>
<%
} else
blnSelected = false;
}
%>

So how i can give the ids different..please suggest me.

adios
05-12-2009, 04:38 PM
That's an asp question, not javascript. But, just a guess ...

<td colspan="2"><input type="checkbox" id="chkBankServices<%=idnum%>" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>

... or something like that, where idnum starts at 1 and then increments after each write. So you end up with:



.....
+ objCustomerService.getServiceID());
%>
<tr>
<td colspan="2"><input type="checkbox" id="chkBankServices1" name="<%=bs.getServiceID()%>" CHECKED><%= bs.getServiceDesc()%>
</td>
</tr>
<%
break;
}
}
}
boolean blnSelected = false;
if(vecResult != null)
for (int i = 0; i < vecResult.size(); i++) {
BankService bs = (BankService) vecResult.elementAt(i);
for (int j = 1; j < vecUpdateCustomerID.size(); j++) {
BankService objCustomerService = (BankService) vecUpdateCustomerID
.elementAt(j);

if (objCustomerService.getServiceID() == bs.getServiceID()) {
blnSelected = true;
break;
}
}
if (!blnSelected) {
%>
<tr>
<td colspan="2"><input type="checkbox" id="chkBankServices2" name="<%=bs.getServiceID()%>"><%=bs.getServiceDesc()%>
</td>
</tr>
........



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum