Hi,
I have been using the following script for a while now and have had 0 problems (thanks to the guy who gave it to me, can't remember who it was)
if(checkB(frmMain))
document.frmMain.submit()
else
alert('Please select at least one Bar')
return false;
}
function checkB(frm){
var flag=0
for (var ii=0; ii<frm.elements.length; ii++){
if (frm.elements[ii].name=='BarID'){
if (frm.elements[ii].checked) flag=-1
}
}
What it does is check the form to see whether any checkboxes have been checked, if they havent it returns an error.
Now i havent needed to use it in conjunction with other checks before and this is where I am having trouble. For some reason it brings up the error whether you check a box or not!
Obviously that isnt very useful, I was wondering if someone here could have a look at the code and find where the bug is? thanks a bunch in advanve
Here is the code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function submitIt(frmMain) {
if (frmMain.NewStaffID.value == "" {
alert("Please assign the Staff Member a Unique ID number"
frmMain.NewStaffID.focus()
return false
}
if (frmMain.Name.value == "" {
alert("Please give them a name."
frmMain.Name.focus()
return false
}
if (frmMain.Position.value == "" {
alert("Please give them a Position."
frmMain.Position.focus()
return false
}
if (frmMain.Mobile.value == "" {
alert("What is their mobile number, please enter none for no mobile."
frmMain.Mobile.focus()
return false
}
if (frmMain.Phone.value == "" {
alert("What is their home phone number?"
frmMain.Phone.focus()
return false
}
if (frmMain.Rate.value == "" {
alert("How much should they be paid?"
frmMain.Rate.focus()
return false
}
if(checkB(frmMain))
document.frmMain.submit()
else
alert('Please select at least one Bar')
return false;
}
function checkB(frm){
var flag=0
for (var ii=0; ii<frm.elements.length; ii++){
if (frm.elements[ii].name=='BarID'){
if (frm.elements[ii].checked) flag=-1
}
}
}
//-->
</SCRIPT>
<table border="1" cellSpacing="0" cellPadding="2" bordercolordark="#000000" bordercolorlight="#000000">
<form autocomplete="off" action=/tools/staff.asp?action=update&mode=update method="post" id="frmMain" name="frmMain" onSubmit="return submitIt(this);submitonce(this);">
<input type="hidden" name="StaffID" value="5612">
<tr>
<td background="/images/rows/dark.gif">Staff ID:</td>
<td background="/images/rows/dark.gif"><input type="text" name="NewStaffID" value="5612" size="5"></td>
</tr>
<tr>
<td background="/images/rows/light.gif">Bar's:</td>
<td background="/images/rows/light.gif">
<table cellSpacing="0" cellPadding="0">
<tr>
<td><input type="checkbox" id="BarID" name="BarID" value="7"></td><td>Calneva</td>
<td><input type="checkbox" id="BarID" name="BarID" value="14"></td><td>Developer</td>
<td><input type="checkbox" id="BarID" name="BarID" value="15" checked="checked"></td><td>Exchange</td>
</tr><tr>
<td><input type="checkbox" id="BarID" name="BarID" value="1"></td><td>Komodo</td>
<td><input type="checkbox" id="BarID" name="BarID" value="2"></td><td>Margaritas Auckland</td>
<td><input type="checkbox" id="BarID" name="BarID" value="13"></td><td>Margaritas Ohakune</td>
</tr><tr>
<td><input type="checkbox" id="BarID" name="BarID" value="11"></td><td>Nancys</td>
<td><input type="checkbox" id="BarID" name="BarID" value="5"></td><td>Provedor</td>
<td><input type="checkbox" id="BarID" name="BarID" value="12"></td><td>Waterfront Cafe</td>
</tr><tr>
</tr>
</table>
</td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Name:</td>
<td background="/images/rows/dark.gif"><input type="text" name="Name" value="JOEY"><input type="hidden" name="arrStaffID" value="5612"></td>
</tr>
<tr>
<td background="/images/rows/light.gif">Position:</td>
<td background="/images/rows/light.gif"><input type="text" name="Position" value="cleaner"> (what do they do?)</td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Mobile Number:</td>
<td background="/images/rows/dark.gif"><input type="text" name="Mobile" value="1234"> (if none type none)</td>
</tr>
<tr>
<td background="/images/rows/light.gif">Phone Number:</td>
<td background="/images/rows/light.gif"><input type="text" name="Phone" value="567"></td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Pay Rate:</td>
<td background="/images/rows/dark.gif">$<input type="text" name="Rate" value="0.5" size="5"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"></td>
</tr>
</form>
</table>
I have been using the following script for a while now and have had 0 problems (thanks to the guy who gave it to me, can't remember who it was)
if(checkB(frmMain))
document.frmMain.submit()
else
alert('Please select at least one Bar')
return false;
}
function checkB(frm){
var flag=0
for (var ii=0; ii<frm.elements.length; ii++){
if (frm.elements[ii].name=='BarID'){
if (frm.elements[ii].checked) flag=-1
}
}
What it does is check the form to see whether any checkboxes have been checked, if they havent it returns an error.
Now i havent needed to use it in conjunction with other checks before and this is where I am having trouble. For some reason it brings up the error whether you check a box or not!
Obviously that isnt very useful, I was wondering if someone here could have a look at the code and find where the bug is? thanks a bunch in advanve
Here is the code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function submitIt(frmMain) {
if (frmMain.NewStaffID.value == "" {
alert("Please assign the Staff Member a Unique ID number"
frmMain.NewStaffID.focus()
return false
}
if (frmMain.Name.value == "" {
alert("Please give them a name."
frmMain.Name.focus()
return false
}
if (frmMain.Position.value == "" {
alert("Please give them a Position."
frmMain.Position.focus()
return false
}
if (frmMain.Mobile.value == "" {
alert("What is their mobile number, please enter none for no mobile."
frmMain.Mobile.focus()
return false
}
if (frmMain.Phone.value == "" {
alert("What is their home phone number?"
frmMain.Phone.focus()
return false
}
if (frmMain.Rate.value == "" {
alert("How much should they be paid?"
frmMain.Rate.focus()
return false
}
if(checkB(frmMain))
document.frmMain.submit()
else
alert('Please select at least one Bar')
return false;
}
function checkB(frm){
var flag=0
for (var ii=0; ii<frm.elements.length; ii++){
if (frm.elements[ii].name=='BarID'){
if (frm.elements[ii].checked) flag=-1
}
}
}
//-->
</SCRIPT>
<table border="1" cellSpacing="0" cellPadding="2" bordercolordark="#000000" bordercolorlight="#000000">
<form autocomplete="off" action=/tools/staff.asp?action=update&mode=update method="post" id="frmMain" name="frmMain" onSubmit="return submitIt(this);submitonce(this);">
<input type="hidden" name="StaffID" value="5612">
<tr>
<td background="/images/rows/dark.gif">Staff ID:</td>
<td background="/images/rows/dark.gif"><input type="text" name="NewStaffID" value="5612" size="5"></td>
</tr>
<tr>
<td background="/images/rows/light.gif">Bar's:</td>
<td background="/images/rows/light.gif">
<table cellSpacing="0" cellPadding="0">
<tr>
<td><input type="checkbox" id="BarID" name="BarID" value="7"></td><td>Calneva</td>
<td><input type="checkbox" id="BarID" name="BarID" value="14"></td><td>Developer</td>
<td><input type="checkbox" id="BarID" name="BarID" value="15" checked="checked"></td><td>Exchange</td>
</tr><tr>
<td><input type="checkbox" id="BarID" name="BarID" value="1"></td><td>Komodo</td>
<td><input type="checkbox" id="BarID" name="BarID" value="2"></td><td>Margaritas Auckland</td>
<td><input type="checkbox" id="BarID" name="BarID" value="13"></td><td>Margaritas Ohakune</td>
</tr><tr>
<td><input type="checkbox" id="BarID" name="BarID" value="11"></td><td>Nancys</td>
<td><input type="checkbox" id="BarID" name="BarID" value="5"></td><td>Provedor</td>
<td><input type="checkbox" id="BarID" name="BarID" value="12"></td><td>Waterfront Cafe</td>
</tr><tr>
</tr>
</table>
</td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Name:</td>
<td background="/images/rows/dark.gif"><input type="text" name="Name" value="JOEY"><input type="hidden" name="arrStaffID" value="5612"></td>
</tr>
<tr>
<td background="/images/rows/light.gif">Position:</td>
<td background="/images/rows/light.gif"><input type="text" name="Position" value="cleaner"> (what do they do?)</td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Mobile Number:</td>
<td background="/images/rows/dark.gif"><input type="text" name="Mobile" value="1234"> (if none type none)</td>
</tr>
<tr>
<td background="/images/rows/light.gif">Phone Number:</td>
<td background="/images/rows/light.gif"><input type="text" name="Phone" value="567"></td>
</tr>
<tr>
<td background="/images/rows/dark.gif">Pay Rate:</td>
<td background="/images/rows/dark.gif">$<input type="text" name="Rate" value="0.5" size="5"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit"></td>
</tr>
</form>
</table>