...

View Full Version : Help needed for JS assignment



Robzy
04-09-2003, 05:15 PM
Before I go bald from pulling my hair out, I hoped maybe someone here may be able to give me a hand. I am to validate a form for this assignment, particularly ensuring the state field is filled, as is the zip code (with numbers, no letters), and at least one checkbox and radio button is checked. Here is the coding from the external JS file. Any help would be greatly appreciated!

function checkItAll()
{
checkState(document.frmCustInfo.ddlState);
checkZip(document.frmCustInfo.txtZip);
editCheckbox(document.frmCustInfo.chkPrice);
editCheckbox(document.frmCustInfo.chkReputation);
editCheckbox(document.frmCustInfo.chkValue);
editCheckbox(document.frmCustInfo.chkRecommendation);
editCheckbox(document.frmCustInfo.chkOtherFactor);
checkEmAll()
theRadioButtons(document.frmCustInfo.rdoUse);
}

// End of checkItAll

// Begin State Verifier

function checkState(field)
{
uSState = field.selectedIndex
if ( uSState == 0)
{
{alert("Please enter an appropriate state.");
}
return false;
}

// End checkState

// Begin Zip Verifier

function checkZip(field){
var allowedOnes = "0123456789"
if (field.value.length == 5)
{
{alert("Please enter a 5 digit zip code.");
return false;
}

for (i=0; i < field.value.length; i++)
{
zipSearch = field.value.substr(i,1)
if (allowedOnes.indexOf(zipSearch) == -1)
{
alert("Please ensure that your zip code is comprised of 5 digits and no other characters.");
return false;
}
}
}
}
// End validateZip

// Begin Checkbox Verifier

var lotsOfCheckboxes = 0
function editCheckbox(){
editCheckbox(document.frmCustInfo.chkPrice)
editCheckbox(document.frmCustInfo.chkReputation)
editCheckbox(document.frmCustInfo.chkValue)
editCheckbox(document.frmCustInfo.chkRecommendation)
editCheckbox(document.frmCustInfo.chkOtherFactor)
if (field.checked) {
lotsOfCheckboxes++
}
else
{
lotsOfCheckboxes--
}
}
function checkEmAll(){
if (lotsOfCheckboxes == 0)
{
alert("Please choose at least one reason you chose to purchase our product.");
return false;
}
}
}
// End the Confusing Checkboxes Verifier

// Beginning the Radiobox Verifier

function theRadioButtons(field){
for (var i = 0; i < field.length; i++) {
if (field[i].checked) {
return;
}
else;{
}
alert("Please choose how you will use the product you purchased.");
}
}


// End Radiobox Verifier

HairyTeeth
04-09-2003, 08:32 PM
hmmm...should i or shouldn't I?
Maybe you should try this sites search facility first, find some validation code and see if you can get it to run...then ask how ;)
Assignments always bring out the sadist in me...[edit: but this may help (http://www.codingforums.com/showthread.php?s=&threadid=17576) ]

liorean
04-09-2003, 08:47 PM
Generally, we don't help in assignments. Asking whether you're on the right track with your own work is quite alright, though.

There's lots of sites that provide tutorials or download scripts to do what you want or something like it, and quite some that will teach you how to write it on your own. Searching these forums or <http://www.wsabstract.com/> might also get you what you want.

Robzy
04-09-2003, 10:31 PM
Well I appreciate the input, and thank you for the links. The frustration is enough to make me want to cry!

Roy Sinclair
04-10-2003, 03:07 PM
To expand on what was implied above. The key here is that we have a vested desire to make sure that you LEARN, as such we don't want to end up writing the code to complete your assignment for you since that wouldn't help you learn. However, we are also here in a large part to learn ourselves so as long as that's your motive for being here you are definitely welcome.

We will even help you with your assignment as long as you have code you're working on and can tell us what part of it you're not quite understanding. We will then try to explain what your code is doing vs what it should be doing (assuming you give us enough to work with). For instance, in all the code you posted I notice that your validation functions are returning FALSE regardless of whether they check passed or failed. Since they return only one value it's impossible for any function calling them to determine whether the value is ok or not. Usually the convention is to return a value of true if the check passed and only return false if the check fails.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum