NOOB HERE, keep getting errors, unexpected end of xml source, variable not defined

Discussion in 'JavaScript' started by Light Speed, Oct 22, 2009.

  1. #1
    im trying to do document(open) and its not working.
    im getting 2 errors.

    - displayNewDocument not defined.
    -unexpected end of xml source.

    i think my mistake is somewhere in my function for displayNewDocument since that part confuses me


    this is the function portion of my script:
    
    function displayNewDocument()
    {
    document.open([averagempg], [gallonsofgas], [reservetank]);
    document.write(<html>);
    document.write('the values you input were '+ averagempg', ' + gallonsofgas +', and' reservetank);
    document.write(/html>);
    document.close();
    }
    
    Code (markup):

    full script

    
    <html>
    
    <script type="text/javascript">
    var averagempg;
    var gallonsofgas;
    var reservetank;
    var gallonsanswer;
    var answer;
    
    
    averagempg = prompt('Please enter your vehicles average mpg rating.');
    gallonsofgas = prompt('Please enter the number of gallons of gasoline currently in your vehicle.');
    reservetank = prompt('Please enter the number of gallons of gasoline in the reserve gas tank of your vehicle.');
    
    averagempg = parseFloat(averagempg);
    gallonsofgas = parseFloat(gallonsofgas);
    reservetank = parseFloat(reservetank);
    
    gallonsanswer= gallonsofgas+reservetank;
    answer = averagempg * gallonsanswer;
    
    
    
    alert('With the available gas you have, you will be able to travel ' + answer + ' more miles.' );
    
    
    function displayNewDocument()
    {
    document.open([averagempg], [gallonsofgas], [reservetank]);
    document.write(<html>);
    document.write('the values you input were '+ averagempg', ' + gallonsofgas +', and' reservetank);
    document.write(/html>);
    document.close();
    }
    
    
    </script></head>
    
    <body onload="displayNewDocument()">
    </body></html>
    Code (markup):
    do i need a function if i want javascript to open a new page and display my variable and some text, or is that where i use an object or something else? im so confused
     
    Last edited: Oct 22, 2009
    Light Speed, Oct 22, 2009 IP
  2. Light Speed

    Light Speed Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    function displayNewDocument()
    {
    document.open([averagempg], [gallonsofgas], [reservetank]);
    Code (markup):
    im pretty sure this is wrong but not sure what.
     
    Light Speed, Oct 22, 2009 IP