www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 01-03-2007, 09:39 AM
    GarethHop GarethHop is offline
    Registered User
     
    Join Date: Jan 2007
    Posts: 20
    won't stop submitting

    I have got a validation script off the internet and for some reason when i perform the checkForm2 and checkForm3 functions they don't stop the form from submitting once the alert has been dismissed.
    below is the code for my validation script.
    the validation script is called via onSubmit on the form.

    any help would be gratefully recieved

    // requires regex to be passed as a parameter
    function checkField(theForm, theField, theFieldDisplay, objRegex)
    {
    objField = eval("document." + theForm + "." + theField);

    if(!objRegex.test(objField.value))
    {
    alert("Please enter a valid " + theFieldDisplay + "")

    objField.select();

    objField.focus();
    objField.style.border = "2px solid #c30"
    return (false);
    }
    objField.style.border = "2px solid #000000";
    return (true);

    }

    // regex for the various form fields


    objReference = /^[0-9]{6}$/;

    objLender = /^[a-zA-Z]{3}$/;

    objTime = /^([0-9]{2})+([:0-9]{3})/;

    objComment = /([a-zA-Z])/;

    objFeedback = /([a-zA-Z]{1,100})/;



    function checkForm(theForm)
    {

    if(checkField(theForm, "reference", "Ref", objReference)
    &&
    checkField(theForm, "lender_code", "Lender Code", objLender)
    &&
    checkField(theForm, "time", "Time hh:mm", objTime))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    function checkForm2(theForm)
    {

    if(checkField(theForm, "comment", "Comment", objComment))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    function checkForm3(theForm)
    {
    if(checkField(theForm, "feedback", "Feedback", objFeedback))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    Reply With Quote
      #2  
    Old 01-03-2007, 11:18 AM
    Kor's Avatar
    Kor Kor is offline
    Red Devil Moderator
     
    Join Date: Dec 2003
    Location: Bucharest, ROMANIA
    Posts: 11,522
    Quote:
    Originally Posted by GarethHop
    the validation script is called via onSubmit on the form.
    How? Can you show us the form tag?
    Reply With Quote
      #3  
    Old 01-03-2007, 11:21 AM
    GarethHop GarethHop is offline
    Registered User
     
    Join Date: Jan 2007
    Posts: 20
    Lightbulb form tag

    <form method=post name="name" onSubmit="checkForm('name')">
    Reply With Quote
      #4  
    Old 01-03-2007, 11:29 AM
    Chikara Chikara is offline
    Registered User
     
    Join Date: Oct 2006
    Posts: 251
    HTML error
    <form method=post name="name" onSubmit="checkForm('name')">

    should be
    <form method=post name="name" onSubmit="return checkForm('name');">
    Reply With Quote
      #5  
    Old 01-03-2007, 11:34 AM
    GarethHop GarethHop is offline
    Registered User
     
    Join Date: Jan 2007
    Posts: 20
    Talking thanks

    thankyou it finally works, now my boss won't gut me!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 10:43 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.