Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help needed for JS assignment

    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

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ]
    Last edited by HairyTeeth; 04-09-2003 at 08:41 PM.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I appreciate the input, and thank you for the links. The frustration is enough to make me want to cry!

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •