| | |
Unable to print results
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 370
Reputation:
Solved Threads: 0
I am doing a small program using a function to print out the real root or imaginary root. The problem is, it only prints out what the numbers that the user input. However, it does not print out the rest.
For Example:
It prints out this:
a = 4 b = 5 c = 3
instead of
a = 4 b = 5 c = 3
root1 = <answer> root2 = <answer>
or
The imaginary number is <answer>
My program is below.
For Example:
It prints out this:
a = 4 b = 5 c = 3
instead of
a = 4 b = 5 c = 3
root1 = <answer> root2 = <answer>
or
The imaginary number is <answer>
My program is below.
javascript Syntax (Toggle Plain Text)
<?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"> <head> <script type = "text/javascript"> function printRoot(a,b,c) { var root1; var root2; var radicand = b*b-4.0*a; var imagpart; var realpart; if (radicand >= 0.0) { root1 = -b+math.sqrt(radicand)/(2.0*a); root2 = -b-math.sqrt(radicand)/(2.0*a); document.writeln("root1 = "+root1+"root2 = "+root2); } else { realpart = -b/(2.0*a); imagpart = math.sqrt(math.abs(radicand))/(2.0*a); document.writeln("The imaginary root is"+realpart+" + "+imagpart+"i"); } } var a; var b; var c; a = window.prompt("Please enter for a"); b = window.prompt("Please enter for b"); c = window.prompt("Please enter for c"); while (a != 0.0) { document.writeln("a = " + a +" b = " + b + " c = " + c); printRoot(a,b,c); } </script> </head> <body> </body> </html>
seems fine but a tip is dont use document.writeln.
try having a content area in the page e.g. a "<div>" then give this element and ID and set its innerHTML property to the text you want.
try having a content area in the page e.g. a "<div>" then give this element and ID and set its innerHTML property to the text you want.
javascript Syntax (Toggle Plain Text)
document.getElementById('someelement').innerHTML += 'your text';
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
![]() |
Similar Threads
- Print Registry Folder Contents (Java)
- Help printing line from file and line number (C++)
- Error from server... (PHP)
- how to view image in Msql (PHP)
- Unable to remove Virus Alert, Pop Ups & IE Start Up page .. help ... (Viruses, Spyware and other Nasties)
- Unable to remove Virus Alert, Pop Ups & IE Start Up page .. help ... (Viruses, Spyware and other Nasties)
- hello and plz help (PHP)
- Getting next and previous row in a MySQL set! (PHP)
- My HiJackThis Log (Viruses, Spyware and other Nasties)
- Error getting forms to send information (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Chained Selects - using Ajax - can't make 3rd one work
- Next Thread: Problem with JavaScript!!! :(
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate automatically beta box bug calendar captcha cart checkbox child class column cookies createrange() css cursor decimal design dom download dropdown editor element engine enter error events explorer file focus form forms frameworks google gwt html htmlform ie8 iframe image() images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jump listbox math matrixcaptcha menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype rated rating regex runtime scale scroll search select session shopping size sql star starrating stars text textarea validation w3c web website window windowofwords windowsxp wysiwyg xml \n





