Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Javascript - validating forms problem

  • 01-09-2004 8:21am
    #1
    Closed Accounts Posts: 509 ✭✭✭


    Hi
    i need help! I am trying to code a registration page and want all the fields to be completed before moving to the next page.

    Here is a snippet of the code! If anyone can help I would really appreciate it!Thanks!

    [COLOR=DarkSlateBlue]
    script language="javascript">

    function ValidateForm(form)
    {
    alert("In function")

    if(IsEmpty(form1.pass))
    {
    alert('Please enter a password')
    form.pass.focus();
    return false;
    }

    if(IsEmpty(form.logInName))
    {
    alert('Please enter a password')
    form.logInName.focus();
    return false;
    }

    return true;

    }

    <form name="form1" action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" onsubmit="javascript:return ValidateForm(this)">
    <table>
    <tr>
    <td colspan="2"> Login Name</td>
    <td><input type="text" value="" name="logInName"></td>
    </tr>
    <tr>
    <td colspan="2">Password</td>
    <td><input type="password" value="" name="pass"></td>
    </tr>
    </table>
    </form>[/COLOR]


Comments

  • Registered Users, Registered Users 2 Posts: 2,243 ✭✭✭zoro


    Try a search engine :)

    Google Search Results for "validate form javascript"

    Top link: Site Link
    More specifically: Using JavaScript to Validate Form Entries

    Good luck :) If you've any more problems then post up here!


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Is that the actual code?

    Two things -
    There's no closing </script> tag.
    There's no submit button.


  • Closed Accounts Posts: 509 ✭✭✭Pinkchick03


    seamus wrote:
    Is that the actual code?

    Two things -
    There's no closing </script> tag.
    There's no submit button.

    Nope but here it is! ;)
    What is happening is - it is going into the function but still going to next page and not going into the ifs!
    Cheers everyone! This is just so annoying!

    here is all the code:

    <SCRIPT>
    function Validate()
    {
    alert("in function")

    logInName=form1.LogInName.value;
    if (LogInName=="")
    {
    alert('LogInName name is a required field. Please try again.');
    event.returnValue=false;
    }

    }
    </SCRIPT>


    </head>

    <body>



    <form name="form1" action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" onsubmit="Validate()">
    <table>
    <tr>
    <td colspan="2"> Login Name</td>
    <td><input type="text" value="" name="logInName"></td>
    </tr>
    <tr>
    <td colspan="2">Password</td>
    <td><input type="password" value="" name="pass"></td>
    </tr>
    <tr>
    <td colspan="2">First Name</td>
    <td><input type="text" value="" name="first"></td>
    </tr>
    <tr>
    <td colspan="2">Last Name</td>
    <td><input type="text" value="" name="second"></td>
    </tr>
    <tr>
    <td colspan="2"> Company</td>
    <td><input type="text" value="" name="company"></td>
    </tr>
    <tr>
    <td colspan="2">Address Line 1 </td>
    <td><input type="text" value="" name="address1"></td>
    </tr>
    <tr>
    <td colspan="2">Address Line 2 </td>
    <td><input type="text" value="" name="address2"></td>
    </tr>
    <tr>
    <td colspan="2">City</td>
    <td><input type="text" value="" name="city"></td>
    </tr>
    <tr>
    <td colspan="2">Postcode</td>
    <td><input type="text" value="" name="pcode"></td>
    </tr>
    <tr>
    <td colspan="2"> Country</td>
    <td><input type="text" value="" name="country"></td>
    </tr>
    <tr>
    <td colspan="2">Phone number</td>
    <td><input type="text" value="" name="phnum"></td>
    </tr>
    <tr>
    <td colspan="2">Fax</td>
    <td><input type="text" value="" name="faxNo"></td>
    </tr>
    <tr>
    <td colspan="2">Email</td>
    <td><input type="text" value="" name="emailad"></td>
    </tr>
    <tr>
    <td><input type="submit" value="Register details" ></td>
    <td><input type="reset" value="Reset" ></td>
    <td></td>
    </tr>
    </table>

    <input type="hidden" name="MM_InsertRecord" value="form1">
    </form>


  • Closed Accounts Posts: 509 ✭✭✭Pinkchick03


    This is the original way I had the code before I looked up search engines (it worked before in another one of my websites :( )

    <script language = "javascript">

    function checkform()
    {
    <!-- alert("in function"); -->

    logInName = true;

    if(document.form1.logInName.value=="")
    { logInName = false;
    alert("Please enter a log in name in the field provided fdiona");
    document.form1.logInName.focus();
    return false;
    }

    pass = true;

    if(document.form1.pass.value=="")
    { pass = false;
    alert("Please enter your password in the field provided");
    document.form1.pass.focus();
    return false;
    }

    first= true;

    if(document.form1.first.value=="")
    { first = false;
    alert("Please enter your first name in the field provided");
    document.form1.first.focus();
    return false;
    }

    second = true;
    if(document.form1.second.value=="")
    { second = false;
    alert("Please enter your last name in the field provided");
    document.form1.second.focus();
    return false;

    }

    company = true;
    if(document.form1.company.value=="")
    { company = false;
    alert("Please enter your company name in the field provided");
    document.form1.company.focus();
    return false;
    }

    address1 = true;

    if(document.form1.address1.value=="")
    { address1 = false;
    alert("Please enter your address line 1 in the field provided");
    document.form1.address1.focus();
    return false;
    }

    address2 = true;

    if(document.form1.address2.value=="")
    {address2= false;
    alert("Please enter your address line 2 in the field provided");
    document.form1.address2.focus();
    return false;
    }

    city = true;

    if(document.form1.city.value=="")
    { city = false;
    alert("Please enter your city in the field provided");
    document.form1.city.focus();
    return false;
    }

    pcode = true;

    if(document.form1.pcode.value=="")
    { pcode = false;
    alert("Please enter your post code in the field provided");
    document.form1.pcode.focus();
    return false;
    }

    country = true;

    if(document.form1.country.value=="")
    { country = false;
    alert("Please enter your country in the field provided");
    document.form1.country.focus();
    return false;
    }

    phnum = true;

    if(document.form1.phnum.value=="")
    { phnum = false;
    alert("Please enter your phone number in the field provided");
    document.form1.phnum.focus();
    return false;
    }

    faxNo = true;

    if(document.form1.faxNo.value=="")
    { faxNo = false;
    alert("Please enter your fax number in the field provided");
    document.form1.faxNo.focus();
    return false;
    }

    email = true;

    if(document.form1.emailad.value=="")
    { email = false;
    alert("Please enter your email address in the field provided");
    document.form1.emailad.focus();
    return false;
    }

    if (second == true & first == true & pass == true & logInName == true & company == true & address1 == true & address2 == true & city == true & pcode == true & country == true & phnum == true & faxNo == true & email == true )
    return true;
    form1.method = "post";
    form1.submit();

    }
    </script>


    </head>

    <body>


    <form name="form1" action="<cfoutput>#CurrentPage#</cfoutput>" method="POST" onsubmit="Validate()">
    <table>
    <tr>
    <td colspan="2"> Login Name</td>
    <td><input type="text" value="" name="logInName"></td>
    </tr>
    <tr>
    <td colspan="2">Password</td>
    <td><input type="password" value="" name="pass"></td>
    </tr>
    <tr>
    <td colspan="2">First Name</td>
    <td><input type="text" value="" name="first"></td>
    </tr>
    <tr>
    <td colspan="2">Last Name</td>
    <td><input type="text" value="" name="second"></td>
    </tr>
    <tr>
    <td colspan="2"> Company</td>
    <td><input type="text" value="" name="company"></td>
    </tr>
    <tr>
    <td colspan="2">Address Line 1 </td>
    <td><input type="text" value="" name="address1"></td>
    </tr>
    <tr>
    <td colspan="2">Address Line 2 </td>
    <td><input type="text" value="" name="address2"></td>
    </tr>
    <tr>
    <td colspan="2">City</td>
    <td><input type="text" value="" name="city"></td>
    </tr>
    <tr>
    <td colspan="2">Postcode</td>
    <td><input type="text" value="" name="pcode"></td>
    </tr>
    <tr>
    <td colspan="2"> Country</td>
    <td><input type="text" value="" name="country"></td>
    </tr>
    <tr>
    <td colspan="2">Phone number</td>
    <td><input type="text" value="" name="phnum"></td>
    </tr>
    <tr>
    <td colspan="2">Fax</td>
    <td><input type="text" value="" name="faxNo"></td>
    </tr>
    <tr>
    <td colspan="2">Email</td>
    <td><input type="text" value="" name="emailad"></td>
    </tr>
    <tr>
    <td><input type="submit" value="Register details" ></td>
    <td><input type="reset" value="Reset" ></td>
    <td></td>
    </tr>
    </table>

    <input type="hidden" name="MM_InsertRecord" value="form1">
    </form>


  • Closed Accounts Posts: 509 ✭✭✭Pinkchick03


    hi everyone
    I got it fixed! Its working now! So happy with myself!
    Cheers for your help :)


  • Advertisement
Advertisement