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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Script Works only some times

    hi,

    i have written some javascript code to validate the form. but the script code executes some times and prompts for the user to enter the values. some times it skips it. i donot know how to solve this problem. whether i have to change any property in the explorer. iam using IE explorer. i am not sure about the versionof it. or should i change the code.

    i have included the code below.

    <SCRIPT LANGUAGE=javascript>
    <!--
    function ValidateId()
    {
    if(document.frmCreateLogin.txtLogin.value=="")
    {
    alert("Enter Login ID");
    document.frmCreateLogin.txtLogin.focus();
    document.frmCreateLogin.txtLogin.select();
    return false;
    }
    else
    {
    if(!isNaN(document.frmCreateLogin.txtLogin.value))
    {
    alert("Invalid User ID");
    document.frmCreateLogin.txtLogin.select();
    return false;
    }
    }
    if(document.frmCreateLogin.txtPass1.value=="")
    {
    alert("Enter First Password");
    document.frmCreateLogin.txtPass1.focus();
    return false;
    }
    if(document.frmCreateLogin.txtpass2.value=="")
    {
    alert("Enter Confirm Password");
    document.frmCreateLogin.txtpass2.focus();
    return false;
    }
    if(document.frmCreateLogin.txtPass1.value != document.frmCreateLogin.txtpass2.value)
    {
    alert("Both passwords should be same");
    document.frmCreateLogin.txtPass1.focus()
    document.frmCreateLogin.txtPass1.select()
    return false;
    }
    return true;
    }
    //-->
    </SCRIPT>
    S.Navaneetha Krishnan

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Are you calling the function like this?
    <form onsubmit="return ValidateId()">
    ...
    <input type="submit" name="btnSubmit" value="Submit">
    </form>

    To make your code efficient, you should pass the form reference to the function.
    <form onsubmit="return ValidateId(this)">

    the this keyword refers to the current element which is the form.

    then in your function:
    function ValidateId(f)
    {
    if(f.txtLogin.value=="")
    ...

    That will save you a lot of typing and more importantly a lot of repetitive referencing.

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry still not working all the time

    dear glenngv,

    i have modified my code as u have said. but still it is not executing this code. what should i do to execute this code compulsorily...some times this validation code is executed and some times not...what is the reason behind it...

    thanks
    S.Navaneetha Krishnan

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Please post the whole code

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry script code not executing

    hi,

    i have posted my whole code here...what is the mistake in the script code...why it is not executing....

    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <BODY>

    <SCRIPT LANGUAGE=javascript>
    <!--
    function Validate(f)
    {
    if(f.txtoldpass.value=="")
    {
    Alert("Enter the Old Password");
    f.txtOldPass.focus();
    return false;
    }
    if(f.txtpass1.value=="")
    {
    alert("Enter the New Password");
    f.txtpass1.focus();
    return false;
    }
    if(f.txtpass2.value=="")
    {
    alert("Enter the Confirm Password");
    f.txtpass2.focus();
    return false;
    }
    return true;
    }
    //-->
    </SCRIPT>

    <FORM Name="frmChangePassword" Method="post" Action="CheckChangePassword.asp" OnSubmit="return validate(this)">
    <pre>
    <P><FONT size=5>&nbsp;<STRONG>
    Change Password</STRONG></FONT></P>
    <STRONG>
    Old Password </STRONG>
    <INPUT name=txtOldPass type=password>
    <P>
    <STRONG>New Password </STRONG>
    <INPUT name=txtPass1 type=password > </P>
    <P><STRONG>Confirm Password </STRONG>
    <INPUT name=txtpass2 type=password></P>
    <P>&nbsp;</P>
    <P>&nbsp;
    <INPUT name=submit type=submit value=Submit onclick="validate()"></P>
    <P></P>
    </pre>
    </FORM>
    </BODY></HTML>
    S.Navaneetha Krishnan

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Javascript is case-sensitive.
    Validate() is different with validate()
    Check all the cases including the use of element names.
    If you name your field as txtOldPass, access it in javascript with the same case.
    Also remove the onclick handler for the submit button.
    The onsubmit handler in the form already does the validation.
    Also turn the javascript error notification for easy debugging.

  • #7
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    dear glenngv,


    thanks for ur valuable reply. i have modified my code as per ur suggestions and now it is working fine.

    Also turn the javascript error notification for easy debugging
    i could not understand the above statement said by u.. what u r trying to say..should i modify it in the IE. if so what property should i change. please be specific. i am new to the web site development.

    thanks & regards
    S.Navaneetha Krishnan

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    In the menu:

    Tools / Internet Options / Advanced / Display a notification after every script error

    If you check that option, any javascript error will be prompted to the user. That will help you in debugging scripts.


  •  

    Posting Permissions

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