Go to Post Stacking totes on end; Gives you extra height, alas; Topples with a sneeze. - BethMo [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2012, 20:17
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Help with website

Hello, my team is working on the website and were trying to do some java script but could not get it to work could someone tell me what is wrong with this simple script.

<html>
<head>

</head>
<body>

<h1>Team #</h1>
<p id="demo"></p>

<button type="button" onclick="displayDate()">Display Date</button>
<script type="text/javascript">

var a =1;
function displayDate()
{
a=a+2;
}

if (a==1)
{
document.getElementById("demo").innerHTML="Hello";
}
else
{
document.getElementById("demo").innerHTML="GoodBye ";
}

</script>

</body>
</html>
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2012, 22:01
HansJ's Avatar
HansJ HansJ is offline
Registered User
AKA: Hans
FRC #3018 (Nordic Storm)
Team Role: Mechanical
 
Join Date: Jan 2010
Rookie Year: 2010
Location: St. Peter
Posts: 29
HansJ is on a distinguished road
Re: Help with website

Add a set of curly braces around the code you want in the function e.g.

Code:
var a =1;
function displayDate()
{
	a=a+2;
	if (a==1)
	{
		document.getElementById("demo").innerHTML="Hello";
	}
	else
	{
	document.getElementById("demo").innerHTML="GoodBye ";
	}
}
The if statement that changes the innerHTML was not being called when you clicked the button, only the addition part

Make sense?
__________________


2013 Lake Superior Excellence In Engineering Winner
2013 Lake Superior Dean's List Finalist
2013 10,000 Lakes Engineering Inspiration Winner
2013 Championship Creativity Award Winner

Last edited by HansJ : 11-02-2012 at 22:12. Reason: clarifying
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2012, 22:41
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: Help with website

First of all, you should ALWAYS begin your HTML files with a doctype.
Code:
<!DOCTYPE html
Your JavaScript should really be in a separate file that is linked in with something like this before the </body> tag:
Code:
<script type="text/javascript" src="js/index.js"></script>
with all your JavaScript being put in the file "index.js" in a "js" subdirectory.

Second of all, I made a little demonstration snippet using JSFiddle, which can be found here: http://jsfiddle.net/ianonavy/cfHpd/

I hope this helps. Continue to post if you have further questions.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2012, 15:16
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Re: Help with website

Thank you I understand what I did wrong. You were big helps.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:48.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi