Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2007, 05:26 AM   PM User | #1
DavidB
New Coder

 
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
DavidB is an unknown quantity at this point
Using Javascript to Write Within the Existing Webpage

Hi, folks.

Is there a way to dynamically write text to an existing webpage with Javascript?

I am writing a page with a solver (in Javascript) that calculates the roots of a quadratic equation.

The user inputs the polynomial coefficients via fields in a form.

I was hoping to output the results neatly below the form using Javascript’s document.write method. This way, if no imaginary components are present, an imaginary field won’t be output at all (to possibly cause confusion among high-school students who have never dealt with imaginary numbers). However, it seems that document.write cannot be used like I want from within an EventHandler-–it would overwrite the existing page. So I cannot simply tell users to click the “Find Roots” button and have the solutions output lower down on the page.

Any suggestions for accomplishing what I want?

Thanks.


David
DavidB is offline   Reply With Quote
Old 02-04-2007, 06:26 AM   PM User | #2
brandonH
Regular Coder

 
Join Date: Oct 2003
Location: on a ship
Posts: 574
Thanks: 1
Thanked 6 Times in 5 Posts
brandonH is on a distinguished road
try innerHTML


create a div or span shere you want the results to show up and do as such:


<span id=results></span>

<script type=text/javascript>

function yourfunction(){

//do your equating here
var result=//what you get from equating
document.getElementById('results').innerHTML=result;
}
</script>
__________________
I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.
brandonH is offline   Reply With Quote
Old 02-04-2007, 06:50 PM   PM User | #3
FJbrian
Regular Coder

 
Join Date: Jun 2002
Location: Adirondacks
Posts: 516
Thanks: 4
Thanked 4 Times in 4 Posts
FJbrian is on a distinguished road
or a javascript to give the form items a value
FJbrian is offline   Reply With Quote
Old 02-06-2007, 02:19 AM   PM User | #4
DavidB
New Coder

 
Join Date: May 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
DavidB is an unknown quantity at this point
Quote:
Originally Posted by brandonH View Post
try innerHTML


create a div or span shere you want the results to show up and do as such:


<span id=results></span>

<script type=text/javascript>

function yourfunction(){

//do your equating here
var result=//what you get from equating
document.getElementById('results').innerHTML=result;
}
</script>

Thanks for the feedback, Brandon.

However, that technique is only applicable for Internet Explorer, isn't it? I'd like my page to work on all browsers.

I'm starting think I will be stuck with a form. I may get rid of having a separate text box for imaginary components, but I will still have at least one text box for each root (if an imaginary component is present, it would just be concatenated with the real part and output in a single textbox). It doesn't give the seamless appearance I would like for my page, but it is better than what I have now.


David
DavidB is offline   Reply With Quote
Old 02-06-2007, 03:40 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
All modern browsers understand innerHTML but if you want to use the method recommended by the standards then read up on the Document Object Model (DOM).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:41 PM.


Advertisement
Log in to turn off these ads.