Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add in further checkbox check in javascript 2

Status
Not open for further replies.

Richey

Technical User
Aug 29, 2000
121
0
0
GB
Hi

I have an existing form which I need to mofidy - I have 2 new checkboxes which i want to validate for if they are both checked = false
I have tried fitting in this check within the existing validation below but it doesn't call it ?
the html for the checkboxes is further below also

any ideas
thanks
kim

Code:
Sub showEnquiryForm(oRSCust,strErr)

	Dim oRS,oRSServices, oRSReasonForCall

    Response.Write "<script src=""include/validate.js"" language=JavaScript></script>" & vbLf
    Response.Write "<script src=""include/adddate.js"" language=JavaScript></script>" & vbLf
	Response.Write "<script language=JavaScript>" & vbLf
    Response.Write "function validateEnquiry()" & vbLf
    Response.Write "{" & vbLf
    Response.Write "  if (document.frmEnquiry.selService.value == '-1') {" & vbLf
	Response.Write "    alert('Please select a Service');" & vbLf
	Response.Write "    document.frmEnquiry.selService.focus();" & vbLf
	Response.Write "    return false;" & vbLf
	Response.Write "    }" & vbLf
	Response.Write "  if (document.frmEnquiry.selRFC.value == '-1') {" & vbLf
	Response.Write "    alert('Please select a Reason for Enquiry');" & vbLf
	Response.Write "    document.frmEnquiry.selRFC.focus();" & vbLf
	Response.Write "    return false;" & vbLf
	Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.selSensitivity.value == '-1') {" & vbLf
	Response.Write "    alert('Please select a Sensitivity');" & vbLf
	Response.Write "    document.frmEnquiry.selSensitivity.focus();" & vbLf
	Response.Write "    return false;" & vbLf
	Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.selSource.value == '-1') {" & vbLf
	Response.Write "    alert('Please select a Enquiry Type/Source');" & vbLf
	Response.Write "    document.frmEnquiry.selSource.focus();" & vbLf
	Response.Write "    return false;" & vbLf
	Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtEnquiryDetails.value == '') {" & vbLf
    Response.Write "    alert('Please enter some Enquiry Details');" & vbLf
    Response.Write "    document.frmEnquiry.txtEnquiryDetails.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtActionsTaken.value == '') {" & vbLf
    Response.Write "    alert('Please enter some Actions Taken');" & vbLf
    Response.Write "    document.frmEnquiry.txtActionsTaken.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtEnquiryDetails.value.length>2000) {" & vbLf
    Response.Write "    alert('Maximum of 2000 characters allowed in Enquiry Details - please edit');" & vbLf
    Response.Write "    document.frmEnquiry.txtEnquiryDetails.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtActionsTaken.value.length>2000) {" & vbLf
    Response.Write "    alert('Maximum of 2000 characters allowed in Actions Taken - please edit');" & vbLf
    Response.Write "    document.frmEnquiry.txtActionsTaken.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtActionsToBeTaken.value.length>2000) {" & vbLf
    Response.Write "    alert('Maximum of 2000 characters allowed in Actions To Be Taken - please edit');" & vbLf
    Response.Write "    document.frmEnquiry.txtActionsToBeTaken.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.txtPersonsContacted.value.length>500) {" & vbLf
    Response.Write "    alert('Maximum of 500 characters allowed in Persons Contacted - please edit');" & vbLf
    Response.Write "    document.frmEnquiry.txtPersonsContacted.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf

    Response.Write "  if (document.frmEnquiry.chkClosed.checked == false) {" & vbLf
    Response.Write "    if (document.frmEnquiry.TargetDate.value=='') {" & vbLf
    Response.Write "      alert('Please provide a Target Date for the Enquiry');" & vbLf
    Response.Write "      document.frmEnquiry.TargetDate.focus();" & vbLf
    Response.Write "      return false;" & vbLf
    Response.Write "      }" & vbLf
    Response.Write "    else {" & vbLf
  	Response.Write "      if (checkDate(document.frmEnquiry.TargetDate.value,new Date(),null)==false) {" & vbLf
    Response.Write "        document.frmEnquiry.TargetDate.focus();" & vbLf
	Response.Write "        return false;" & vbLf
	Response.Write "        }" & vbLf
    Response.Write "      }" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "  if (document.frmEnquiry.chkClosed.checked == true &&" & vbLf
    Response.Write "       document.frmEnquiry.chkUrgent.checked == true) {" & vbLf
    Response.Write "    alert('Cannot CLOSE an URGENT Enquiry!');" & vbLf
    Response.Write "    document.frmEnquiry.chkUrgent.focus();" & vbLf
    Response.Write "    return false;" & vbLf
    Response.Write "    }" & vbLf
    Response.Write "		return true;" & vbLf
    Response.Write "}" & vbLf


html code
Code:
'rh amends - custom fields for Glass
    Response.Write "        <tr>" & vbLf
    Response.Write "          <td colspan=2><span class=clsMainText>Enquiry relates to: </span><b>Missed Bin</b>"
    Response.Write "          <input type=checkbox " & IIf(Request("missedbin")="on","CHECKED","") & " name=chkmissedbin>" & 

vbLf
    Response.Write "          <b>etc etc</b>" & vbLf
    Response.Write "          <input type=checkbox " & IIf(Request("missedbin1")="on","CHECKED","") & " name=chkmissedbin1>" 

& vbLf
    Response.Write "        </td>" & vbLf
    Response.Write "        </tr>" & vbLf
 
sorry !

Code:
<script language=JavaScript>
function validateEnquiry()
{
  if (document.frmEnquiry.selService.value == '-1') {
    alert('Please select a Service');
    document.frmEnquiry.selService.focus();
    return false;
    }
  if (document.frmEnquiry.selRFC.value == '-1') {
    alert('Please select a Reason for Enquiry');
    document.frmEnquiry.selRFC.focus();
    return false;
    }
  if (document.frmEnquiry.selSensitivity.value == '-1') {
    alert('Please select a Sensitivity');
    document.frmEnquiry.selSensitivity.focus();
    return false;
    }
  if (document.frmEnquiry.selSource.value == '-1') {
    alert('Please select a Enquiry Type/Source');
    document.frmEnquiry.selSource.focus();
    return false;
    }
  if (document.frmEnquiry.txtEnquiryDetails.value == '') {
    alert('Please enter some Enquiry Details');
    document.frmEnquiry.txtEnquiryDetails.focus();
    return false;
    }
  if (document.frmEnquiry.txtActionsTaken.value == '') {
    alert('Please enter some Actions Taken');
    document.frmEnquiry.txtActionsTaken.focus();
    return false;
    }
  if (document.frmEnquiry.txtEnquiryDetails.value.length>2000) {
    alert('Maximum of 2000 characters allowed in Enquiry Details - please edit');
    document.frmEnquiry.txtEnquiryDetails.focus();
    return false;
    }
  if (document.frmEnquiry.txtActionsTaken.value.length>2000) {
    alert('Maximum of 2000 characters allowed in Actions Taken - please edit');
    document.frmEnquiry.txtActionsTaken.focus();
    return false;
    }
  if (document.frmEnquiry.txtActionsToBeTaken.value.length>2000) {
    alert('Maximum of 2000 characters allowed in Actions To Be Taken - please edit');
    document.frmEnquiry.txtActionsToBeTaken.focus();
    return false;
    }
  if (document.frmEnquiry.txtPersonsContacted.value.length>500) {
    alert('Maximum of 500 characters allowed in Persons Contacted - please edit');
    document.frmEnquiry.txtPersonsContacted.focus();
    return false;
    }
  if (document.frmEnquiry.chkClosed.checked == false) {
    if (document.frmEnquiry.TargetDate.value=='') {
      alert('Please provide a Target Date for the Enquiry');
      document.frmEnquiry.TargetDate.focus();
      return false;
      }
    else {
      if (checkDate(document.frmEnquiry.TargetDate.value,new Date(),null)==false) {
        document.frmEnquiry.TargetDate.focus();
        return false;
        }
      }
    }
  if (document.frmEnquiry.chkClosed.checked == true &&
       document.frmEnquiry.chkUrgent.checked == true) {
    alert('Cannot CLOSE an URGENT Enquiry!');
    document.frmEnquiry.chkUrgent.focus();
    return false;
    }
		return true;
}

html.................

Code:
<tr>
<td colspan=2><span class=clsMainText>Enquiry relates to: </span><b>Missed Bin</b><input type=checkbox  name=chkmissedbin>
<b>etc etc</b>
<input type=checkbox  name=chkmissedbin1>
</td>
</tr>
 
Before trying to give you an answer, I'd strongly suggest you give to use the getElementById-method to refer to form elements. Next, try to stick to the W3C HTML standards, e.g. use " " by assigning values to tags. Especially strict browsers (like Mozilla and Opera) will - sooner or later - complain and behave strangely otherwise.

This should work:

Code:
<tr>
<td colspan="2">
<span class="clsMainText">Enquiry relates to: </span><b>Missed Bin</b>
<input type="checkbox" name="chkmissedbin" id="chkmissedbin">
<b>etc etc</b>
<input type="checkbox" name="chkmissedbin1" id="chkmissedbin1">
</td>
</tr>

The Javascript code to check these is:
Code:
if (document.getElementById('chkmissedbin').checked==false)
{
  alert('chkmissedbin is not checked');
}
else
{
  alert('chkmissedbin is checked');
}

if (document.getElementById('chkmissedbin1').checked==false)
{
  alert('chkmissedbin1 is not checked');
}
else
{
  alert('chkmissedbin1 is checked');
}
 
thanks rekcor

I'll take note of that for the future, problem is I've inherited this 3rd party software product and I don't want to (and haven't the time) at this early stage to re-write the whole thing, so that code is their's - I just can't seem to add validation for my custom fields (missedbin and missedbin1) even so for the next month or so I'll have to stick to their code - I've got 14 of these to do !
I only want the validation to kick in of both missedbin and missedbin1 are false.

thanks
 
Ok I understand. Try this:

Code:
<tr>
<td colspan="2">
<span class="clsMainText">Enquiry relates to: </span><b>Missed Bin</b>
<input type="checkbox" name="chkmissedbin">
<b>etc etc</b>
<input type="checkbox" name="chkmissedbin1">
</td>
</tr>

The Javascript code to check these is:

[code]
if (document.frmEnquiry.chkmissedbin.checked == false && document.frmEnquiry.chkmissedbin1.checked == false)
{
  alert('Both chkmissedbin and chkmissedbin1 are false');
}


 
>I only want the validation to kick in of both missedbin and missedbin1 are false.

In that case, at the place of return true line, insert this before it.
[tt]
//return true //at the original
if (!document.frmEnquiry.chkmissedbin.checked && !document.frmEnquiry.chkmissedbin1.checked) {
//validation to kick in
return false;
}
return true;
[/tt]
In your asp, that means
[tt]
'Response.Write " return true;" & vbLf
Response.Write "if (!document.frmEnquiry.chkmissedbin.checked && !document.frmEnquiry.chkmissedbin1.checked) { " & vbLf
Response.Write " //validation to kick in" & vbLf
Response.Write " return false;" & vbLf
Response.Write "}" & vbLf
Response.Write "return true;" & vbLf
[/tt]
Only thing is to make it look as "pretty" as your original by adding more spaces around etc. But that's cosmetic. The same principle applies if you have more to add as said.
 
thank you everyone - works a treat
Rekcor - I have given your earlier post a star also because once i rewrite them completely i will take that into account

thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top