Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Javascript not working in ie8

  1. #1
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default Javascript not working in ie8

    Hi All,

    the below code is not working in ie8,

    <script type="text/javascript">
    <!--

    function validate_form ( )
    {

    valid = true;

    var pattern=/([A-Za-z]{2,20}$)+/


    else if (!pattern.test(document.newform.name.value) )
    {
    alert ( "Please enter the missing value" );
    document.newform.name.focus();
    valid = false;
    }

    valid=true;
    }
    ..>
    </script>

    <form action="valid.php" method="post" name=newform onsubmit="return validate_form ( );">
    <table>
    <tr><td>Name</td><td><input type=text name="name" ></td></tr>
    </table>


    I am able to get the validation in chrome and firefox. But i need it in ie8 also, can anyone help me in this

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    IE might not like the name of your form. Try putting the name in quotes

    so

    Code:
    name=newform
    becomes

    Code:
    name="newform"
    Corrections to my coding/thoughts welcome.

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    hemi519 (12-13-2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    thanks for that, iam having another doubt, in the form tag, action=someotherpage.php(not the page where i written this html and javascript page ) can i do validations in that also. iam unable to do so, it is showing for the first filed and automatically redirecting to someotherpage.php. how to stop this.

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I'm not exactly clear what you mean by validation ((x)html valid or data input valid). The action attribute is where the form will go to be processed.
    Corrections to my coding/thoughts welcome.

  6. #5
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    if my page is valid.html and if my action=reg.html will that work with the perfect validation. In my case after the first field validation it is directly redirecting to reg.html, it is not asking for the second field. how can i do that

  7. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Please post your full code or a link.
    Corrections to my coding/thoughts welcome.

  8. #7
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    -------valid.html--------------

    in action tag <form action=validd.html>

    <html>
    <head>
    <script type="text/javascript">

    <!--
    function validate_form ( )
    {

    valid = true;

    var pattern=/([A-Za-z]{2,20}$)+/;


    if (!pattern.test(document.newform.name.value) )
    {
    alert ( "Please enter the missing value" );
    document.new.nameform.focus();
    valid = false;
    }


    else if (!pattern.test(document.newform.name1.value) )
    {
    alert ( "Please enter the missingc2 value" );
    document.newform.name1.focus();
    valid = false;
    }

    alert("DDD");

    return valid;
    }
    -->
    </script>
    </head>
    <body>
    <form action="validd.html" method="post" name="newform" onsubmit="return validate_form ( );">
    <table>
    <tr><td>Name</td><td><input type=text name="name" ></td></tr>
    <tr><td>Name</td><td><input type=text name="name1" ></td></tr>
    <tr><td> <input type=submit > </td></tr>
    </table>
    </form>
    </body>
    </html>

  9. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You don't need the form at all for this, I think. The part I think that was throwing you off was the else.


    Code:
    <head>
    <script type="text/javascript">
    <!--
    function validate_form ( ){
    	valid = true;
    	var pattern=/([A-Za-z]{2,20}$)+/;
    	if (!pattern.test(document.newform.name.value) ) {
    		alert ( "Please enter the missing value" );
    		document.new.nameform.focus();
    		valid = false;
    	}
    	if (!pattern.test(document.newform.name1.value) ) {
    		alert ( "Please enter the missingc2 value" );
    		document.newform.name1.focus();
    		valid = false;
    	}
    	alert("DDD");
    	return valid;
    }
    -->
    </script>
    </head>
    <body>
    <table>
    	<tr>
    		<td>Name</td>
    		<td><input type="text" name="name" ></td>
    	</tr>
    	<tr>
    		<td>Name</td>
    		<td><input type="text" name="name1" ></td>
    	</tr>
    	<tr>
    		<td><input type="submit" onClick="return validate_form ( );" > </td>
    	</tr>
    </table>
    </body>
    Corrections to my coding/thoughts welcome.

  10. #9
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    u removed my form tag, i want that form tag with action to different page

  11. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Oh, I thought you were going to the same page. You can just through it back in there than. If the user has JS turned off though this validation won't be performed usually this is passed to a server side page were an additional validation is performed if the data is suppose to be secure.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function validate_form ( ){
    	valid = true;
    	var pattern=/([A-Za-z]{2,20}$)+/;
    	if (!pattern.test(document.newform.name.value) ) {
    		alert ( "Please enter the missing value" );
    		document.new.nameform.focus();
    		valid = false;
    	}
    	if (!pattern.test(document.newform.name1.value) ) {
    		alert ( "Please enter the missingc2 value" );
    		document.newform.name1.focus();
    		valid = false;
    	}
    	alert("DDD");
    	return valid;
    }
    -->
    </script>
    </head>
    <body>
    <form action="validd.html" method="post" name="newform" onsubmit="return validate_form ( );">
    <table>
    	<tr>
    		<td>Name</td>
    		<td><input type="text" name="name" ></td>
    	</tr>
    	<tr>
    		<td>Name</td>
    		<td><input type="text" name="name1" ></td>
    	</tr>
    	<tr>
    		<td><input type="submit"> </td>
    	</tr>
    </table>
    </form>
    </body>
    </html>
    Corrections to my coding/thoughts welcome.

Bookmarks

Posting Permissions

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