help editing a degree conversion code i wrote!

Discussion in 'JavaScript' started by edwin1222, Apr 21, 2008.

  1. #1
    can someone hlep me editing these code? something is wrong, and i want the pop-up window close after the conversion and show the result at original page, how do i do that?

    ============================
    <html>
    <head>
    <title>JavaScript Assignment 4 Part 1</title>
    </head>
    <body>

    <script language="JavaScript">
    <!--

    function open_new_window(){

    new_window=open("","hoverwindow","width=300,height=500,left=100,top=100");

    new_window.document.open();

    new_window.document.write('<html>'); );
    new_window.document.write('<html>);
    new_window.document.write('<head>);
    new_window.document.write('<script type="text/javascript">);
    new_window.document.write('function get(eid) {);
    new_window.document.write('var d = document; );
    new_window.document.write('var r = d.getElementById(eid); );
    new_window.document.write('return r; );
    new_window.document.write('});

    new_window.document.write('function convert() {);
    new_window.document.write('var f = get('F').value; );
    new_window.document.write('var c = Math.round(5*(f-32)/9); );
    new_window.document.write('var degreesC = get('C'); );
    new_window.document.write('degreesC.innerHTML = 'Degrees Celsius: ' + c; );

    new_window.document.write('});
    new_window.document.write('</script>);
    new_window.document.write('</head>);
    new_window.document.write('<body>);
    new_window.document.write('<form>);
    new_window.document.write('Enter degrees Fahrenheit: );
    new_window.document.write('<input type="text" id="F" />);
    new_window.document.write('<input type="button" onclick="convert()" value="convert temperature" />);
    new_window.document.write('<div id="C"> </div>);
    new_window.document.write('</form>);
    new_window.document.write('</body>);
    new_window.document.write('</html>);


    new_window.document.close();
    }


    </script>



    <a href="#" onclick="open_new_window()">Welcome to the Temperature Calculator</a>





    </body>
    </html>
     
    edwin1222, Apr 21, 2008 IP
  2. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Rather than do your homework for you, here are some places to start:

    1. Remove one of the two <html> tags that are being written to the new window. It doesn't matter which one you eliminate, because both of them have an error.
    2. Close your quotes.
    3. Practice consistency: you used <script language="JavaScript"> and then later used <script type="text/javascript">. The latter choice is the better one.
    4. Unless specifically required for this assignment, eliminate the get() function and just use document.getElementById() directly.
    5. Do not use single quotes within a string that was started with a single quote, unless you escape them.
    6. Escape the </script> tag that is being written with script.
    7. Close the comment tag.

    Nothing in the code for the new window closes it or passes a value back to the opener, so I'm not sure how you were expecting that to work. Is there some reason why you can't just do it all in on the same page?
     
    vpguy, Apr 21, 2008 IP