|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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> |
|
#2
|
||||
|
||||
|
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 ";
}
}
Make sense? Last edited by HansJ : 11-02-2012 at 22:12. Reason: clarifying |
|
#3
|
|||
|
|||
|
Re: Help with website
First of all, you should ALWAYS begin your HTML files with a doctype.
Code:
<!DOCTYPE html Code:
<script type="text/javascript" src="js/index.js"></script> 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. |
|
#4
|
|||
|
|||
|
Re: Help with website
Thank you I understand what I did wrong. You were big helps.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|