| | |
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: 365
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 |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





