By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

How to display return results on my HTML page?

pgrDaniel
P: 3
Here is the HTML doc:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2.  <html>
  3.  <head>
  4.  <title>Testing a webpage</title>
  5.  <link rel="stylesheet" type="text/css" href="myStyle.css">
  6.  <script src="converter.js"></script>
  7.  </head>
  8.  
  9.  <body>
  10.  
  11.    <form>
  12. //input some data
  13.  
  14.     <input type="button" onclick=converter(70,"fahrenheit") value="TRY">
  15.    </form>
  16.  
  17.     <p>"Result is "</p>
  18.     <script type="text/javascript" document.write(converter[0])></script>
  19.  
  20.  </body>
  21.  
  22.  </html>
  23.  
Here is External .js file:

Expand|Select|Wrap|Line Numbers
  1. function converter(n, from)
  2. {
  3. var res=[];
  4.  
  5. if(from == "fahrenheit")
  6. {
  7.     document.write(n);
  8.     document.write("<br />");
  9.     document.write(from);
  10.  
  11.     res[0] = ((5/9.0)*(n-32));
  12.     res[1] = ((5/9.0)*(n-32)+273.15);
  13.     document.write("<br />");
  14.  
  15. //confirm data passed
  16.  
  17.     document.write("here is the result in celcius: func converter calculated: ",res[0]);
  18.     document.write("<br />");
  19.     document.write("here is the result in kelvin: func converter calculated: ",res[1]);
  20.     return res;   //??
  21. }
  22. }
  23.  
//The data gets passed and the calculations get done here no problem, the problem happens is I cant seem to display the results in the HTML file....its like the values dont get returned back?
Aug 17 '13 #1

✓ answered by Dormilich

the problem happens is I cant seem to display the results in the HTML file
thatís because document.write() has already erased your page, including the JavaScript to display the result.

Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the problem happens is I cant seem to display the results in the HTML file
thatís because document.write() has already erased your page, including the JavaScript to display the result.
Aug 17 '13 #2

pgrDaniel
P: 3
Yes I see how that can be a problem...thank you. How am I going to output the answers in HTML page?
Aug 18 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
you can create HTML elements with built-in DOM methods like createElement(), innerHTML, etc.
Aug 18 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.