/    Sign up×
Community /Pin to ProfileBookmark

Have a better handle on what the problem is Help

ok I have error checking as listed below:I want to add to it as outlined below – it should be very easy but for some reason when I add the error it does not work – I have tried a multitude of variations. Please help – I believe I have explained it precisely but let me know if you need additional info.

Thanks,:eek:

</SCRIPT>
<FORM ACTION=”/ekeck/new-account/indexhld.phtml” METHOD=”POST” NAME=”SignupForm” ONSUBMIT=”return CheckFields();”>

<SCRIPT LANGUAGE=”JavaScript”>
function CheckFields() {
var Errors = “”;

Errors += document.SignupForm.FirstName.value == “” ? “You did not enter the first name.n” : “”;
Errors += document.SignupForm.LastName.value == “” ? “You did not enter the last name.n” : “”;
Errors += document.SignupForm.JobTitleID.value == “” ? “You did not select a job title.n” : “”;
Errors += document.SignupForm.DepartmentID.value == “” ? “You did not select a department.n” : “”;

if (Errors != “”) {
alert(Errors);
return false;
} else {
return true;
}
}

</SCRIPT>

elsewhere in the program I have the following array defined with an identifying number that is brought back into the program to update a database when something is checked:

<TR>
<TD COLSPAN=”2″ ALIGN=”CENTER”>
<BR><B>Access Modules</B><BR>

<INPUT TYPE=”CHECKBOX” NAME=”Access[1]”>PatientCare</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[2]”>OrderEntry</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[3]”>Department Desc 1</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[4]”>Kodak PACS</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[8]”>OmniCell</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[6]”>Some View</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE=”CHECKBOX” NAME=”Access[7]”>Another Dept</B>&nbsp;&nbsp;&nbsp;&nbsp;
</TD>
</TR>

I want to be able to add another error check to the checkfields() function above that if Access[8] is checked than they must also select Staff
Type which is defined under the array as a drop down:

<TR>
<TD ALIGN=”CENTER” COLSPAN=”5″>
<BR> <B> If OmniCell Please Select One: </B> <BR>
</TD>
</TR>

<TR>
<TD ALIGN=”CENTER” COLSPAN=”2″>

<SELECT NAME=”StaffType”>
<OPTION VALUE= ” “>Select Staff Type</OPTION>
<OPTION VALUE=”Staff”>Staff</OPTION>
<OPTION VALUE=”Coordinator/Supervisor”>Coordinator/Supervisor</OPTION>
</SELECT>
</TD>
</TR>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJul 24.2008 — You'll want to rename your Access[] fields and give each one a value. This will make your life MUCH easier on the JavaScript side. Then $_POST['Access'] will be an array of numbers:
[code=html]<INPUT TYPE="CHECKBOX" NAME="Access[]" value="1">PatientCare</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="2">OrderEntry</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="3">Department Desc 1</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="4">Kodak PACS</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="5">OmniCell</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="6">Some View</B>&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="Access[]" value="7">Another Dept</B>&nbsp;&nbsp;&nbsp;&nbsp;[/code]

Now the JavaScript:
function CheckFields(form) {
var errors = [];

if ( emptyField(form.elements.FirstName) ) {
errors.push("You did not enter the first name.");
}

if ( emptyField(form.elements.LastName) ) {
errors.push("You did not enter the last name.");
}

if ( emptyField(form.elements.JobTitleID) ) {
errors.push("You did not select a job title.");
}

if ( emptyField(form.elements.DepartmentID) ) {
errors.push("You did not select a department.");
}

if ( getCheckedValue(form.elements["Access[]"]) == "8" &amp;&amp; emptyField(form.elements.StaffType) ) {
errors.push("You did not select a staff type.");
}

if (errors.length &gt; 0) {
alert(errors.join("n"));
return false;
} else {
return true;
}

}

function getCheckedValue(els) {
var i = 0;
var end = els.length;
var el;

while (el = els[i++]) {
if (el.checked) {
return el.value
}
}
return "";
}

function emptyField(el) {
return (el.value != "") ? true : false;
}


Lastly, change the onsubmit for your FORM:
&lt;FORM ... ONSUBMIT="return CheckFields([B]this[/B]);"&gt;

EDIT: Corrected syntax error in the alert()
Copy linkTweet thisAlerts:
@ProgessauthorJul 24.2008 — my problem is this.

The array is being populated with a module id number in the name which is used to update a file later on. I had the same thought as you but this is the problem. Thank you sooooo much for your reply I have been checking and hoping someone would answer. please let me know what your thoughts are - besides that it is crazy to put the id # in - I inherited the code and I am just trying to make this one stupid change?
Copy linkTweet thisAlerts:
@toicontienJul 24.2008 — You can loop over the [B]form.elements[/B] array, and check the name property to see if the name is "Access[8]":
var i = 0;
var end = form.elements.length;
var el;

while (el = form.elements[i++]) {
if ( el.name == "Accept[8]" &amp;&amp; el.checked &amp;&amp; emptyField(form.elements.StaffType) ) {
errors.push("You did not select a staff type.");
}
}
Copy linkTweet thisAlerts:
@ProgessauthorAug 04.2008 — ? Thank you sooo much you are awesome This took too much of my time and was a humbling experience?
×

Success!

Help @Progess spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...