Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 10-08-2007, 10:51 AM   #1
Baseband Member
 
Join Date: Sep 2007
Posts: 28
Send a message via AIM to compwebnut777
Default Javascript Issue

Hey guys, having a bit of a problem with some Javascript I wrote for class. When it runs, it fails, as in white screen instead of a prompt box. Anyone know what's going on? I'll put the code in real quick:

Code:
<html>
<head>

</head>
<body>

<script type="text/javascript">

alert("hi");


var birthmonth = parseInt(prompt("Please enter your month of birth",""));

if(birthmonth == 11){
   birthmonth = 2;
}

var birthdate = parseInt(prompt("Please enter your date of birth",""));

if(birthdate == 14){
   birthdate = 5;
}

var birthyear = parseInt(prompt("Please enter your year of birth",""));

if(birthyear == 1989}{
   birthyear = 9;
}


document.write(birthmonth);
document.write(birthdate);
document.write(birthyear);

</script>

</body>
</html>
What I'm trying to do is get the numbers 2, 5 and 9 to show up on the screen. I'm new to this (hence the probably basic code) and I don't have a clue what is going on, so any help would be greatly appreciated .
__________________

compwebnut777 is offline   Reply With Quote
Old 10-09-2007, 03:45 PM   #2
Fully Optimized
 
Join Date: Jun 2005
Posts: 3,275
Send a message via ICQ to DJ Stephen Send a message via AIM to DJ Stephen Send a message via MSN to DJ Stephen Send a message via Yahoo to DJ Stephen
Default Re: Javascript Issue

I think it might becuase becuase you are setting the var as the prompt, then setting it as an integer. maybe a different name?
__________________

DJ Stephen is offline   Reply With Quote
Old 05-18-2009, 09:45 AM   #3
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: Javascript Issue

Try this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" dir="ltr">
 <head>
  <meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />
  <title>Javascript Test</title>
  <script type="text/javascript">
   <!--

   //Declare variables//
    var bMonth = 0;
    var bDate = 0;
    var bYear = 0;
    var outputMonth = 0;
    var outputDate = 0;
    var outputYear =0;
   //End Declare Variables//

   //Get Values//
    bMonth = prompt("Please enter your Month of birth.","");
    bDate = prompt("Please enter your Date of birth.","");
    bYear = prompt("Please enter your Year of birth.","");
   //End Get Values//

   //Validate values//
    if(Number(bMonth).toString() == "NaN") {
      document.write("That is not a valid Month.<br />Please re-load the page and try again.");
    } else if(Number(bMonth) == 0) {
      document.write("You must enter a birth Month.<br />Please re-load the page and try again.");
    } else if(Number(bMonth) == 11) {
      outputMonth = 2;
      document.write(outputMonth);
    } else {
      document.write("Unknown Error on birth Month.<br />Please re-load the page and try again.<br />");
    } // end if/else

    if(Number(bDate).toString() == "NaN") {
      document.write("That is not a valid Date.<br />Please re-load the page and try again.<br />");
    } else if(Number(bDate) == 0) {
      document.write("You must enter a birth Date.<br />Please re-load the page and try again.<br />");
    } else if (Number(bDate) == 14) {
      outputDate = 5;
      document.write(outputDate);
    } else {
      document.write("Unknown Error on birth Date.<br />Please re-load and try again.<br />");
    } // end if/else

    if(Number(bYear).toString() == "NaN") {
      document.write("That is not a valid Year.<br />Please re-load the page and try agian.<br />");
    } else if(Number(bYear) == 0) {
      document.write("You must enter a valid birth Year.<br />Please re-load the page and try again.<br />");
    } else if(Number(bYear) == 1989) {
      outputYear = 9;
      document.write(outputYear);
    } else {
      document.write("Unknown Error on birth Year.<br />Please re-load the page and try again.<br />");
    } // end if/else
   //End Validate Values//

   //-->
  </script>
 </head>
 <body>
 </body>
 </html>
__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 05-18-2009, 10:39 AM   #4
Baseband Member
 
Join Date: Sep 2004
Posts: 95
Default Re: Javascript Issue

It looks like you may have a typo. You have a } where you need a ).

It happens in the following lines:

Code:
if(birthyear == 1989}{
   birthyear = 9;
}
It should be:

Code:
if(birthyear == 1989){
   birthyear = 9;
}
__________________
As the sun sets, the earth shall prepare
ksb007 is offline   Reply With Quote
Old 05-30-2009, 03:11 PM   #5
Beta Member
 
Join Date: May 2009
Posts: 1
Default Re: Javascript Issue

Hi there

Have just found this site and I'm in London. Am doing some computing studies with the Open University and have bitten off more than I can chew!!! Can anyone tell me how to declare a variable in Javascript when the quantities are unknown, e.g. the number of runners in a race?

Many thanks and best wishes
Carol Roy
carolroy52 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:55 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0