2 Replies - 153 Views - Last Post: 02 September 2018 - 09:41 AM

#1 sonar87   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 04-February 08

Javascript and button not doing anything

Posted 02 September 2018 - 09:14 AM

I'm trying to learn javascript and have tried to include js from external file in my html code. Though none of the js is doing anything. The stuff from document.write not showing up anywhere, and the login div not being changed when the botton clicked. Or when should be changed by the document.getElementById("login").innerHTML = "xx"; Tutorial said out "return [function name]()" in the onclick attribute. Must something else be done?

<!DOCTYPE html>
<html lang = "en">

	<head>
		<title>Home</title>
		<meta charset = "utf-8"/>
		<link rel = "stylesheet" href = "Style.css">
	</head>

	<body>

	<script type = "text/javascript" src = "P1.Submit.js"></script>

	<div id ="bodyDiv">

		<h2 class = "pgTitle">Home</h2>
			
		<hr/>
		<div id = "login">
			<form action = "" method = "post">
		
			<lable>Username: <input type = "text" name = "uname" id = "uname" maxlength = "10" size = "10" /> </lable>   

			<lable>Password: <input type = "password" name = "pass" id = "pass" maxlength = "20" size = "20" /> </lable>   			
			
			<input type = "submit" value = "submit" id = "submitButton" onclick = "return process()"/>			

			</form>
		</div>

		<hr/>

		<br/>

		<p>Welcome!</p>
	
	
	</div>	

	</body>
</html>




.js file:

var button = document.getElementById('submitButton');

document.write("flsdffsdhk");
document.getElementById("login").innerHTML = "xx";

function process()
{
	var rand = math.random();
	document.getElementById("login").innerHTML = rand;
	return false;
}



This post has been edited by sonar87: 02 September 2018 - 09:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Javascript and button not doing anything

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14434
  • View blog
  • Posts: 57,858
  • Joined: 12-June 08

Re: Javascript and button not doing anything

Posted 02 September 2018 - 09:23 AM

I would check to make sure the files are in the same folder.
Then, in your browser, hit f12 for the developer tools. Click the 'console' tab. Now do your actions on your page. You should be getting some errors you need to fix.

Quote

[Show/hide message details.] ReferenceError: math is not defined[Learn More] New Text document.html:17:6
process
[Show/hide message details.] TypeError: document.getElementById(...) is null[Learn More] New Text document.html:12:1

Was This Post Helpful? 1
  • +
  • -

#3 sonar87   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 04-February 08

Re: Javascript and button not doing anything

Posted 02 September 2018 - 09:41 AM

Thank you. Good to now know how to get debugging/error message things. Have gotten it working now. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1