Javascript onClick does not open page under action

Submit button does not open a page WelocmeToTesting.html. Can someone please help here?

Login Page


Not without seeing your code.

<html><head><title>Login Page</title><head>
<script language="JavaScript" type="text/JavaScript">
<!--//hide script
function checkme()
	 var _invalidChars = new Array("!","@");
	 var _str = document.f1.Uid.value;
	 var _chr = _str.charAt(1);
	 for(var i = 0; i < _str.length; i++)
	  _chr = _str.charAt(i);           
	  for(var j = 0; j < _invalidChars.length; j++)
	   if(_chr == _invalidChars[j])
	    alert("You have entered an invalid character for User Id.");
	    return false

	return true;
// --->
<form name="f1" id="FrmId" action="./WelocmeToTesting.html" method="post">
<DIV align=center><table border="1" bgcolor="6A5ACD">
  <tr><td><br>UserId<input name="Uid"><br><br>
  <input type="button" value="Submit" name="Submit0" onClick="JavaScript:checkme()">

I posted the code in java code format.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you. I will remember it for next time…

Have you tried looking in the JS console for errors? That’s where I would start.

I just joined the forum and did not look into JS console yet. How do I go to JS console?

The code gives proper error message when user enters special character (! or @) but when user enters correct data then it does not open a page.

Google: “How to open browser console”


Thank you. I just checked in JS Console of chrome and found below error.
Uncaught TypeError: Cannot read property ‘submit’ of undefined

I am running this script from my C drive.

Correct, it is telling you that you are trying to call the method submit() on a value that is undefined. This is the line it is complaining about:


So it is saying that document.FrmId is undefined (i.e. it doesn’t exist). Your job is to figure out how to make this line work. My recommendation:

Google: “javascript form submit method”

Make sure you are using the submit method properly.

But From id has been already defined.

<form name="f1" id="FrmId" action="./WelocmeToTesting.html" method="post">

Yes, the form has an id. Now you need to access the form correctly using the id.

Google: “javascript access element by id”

The problem is the following line:


document does not have a property named FrmId. You can reference window and it will have such a property.

Thank you for your guidance. I was able to resolve the issue.