[Javascript] Printing out (?)

vern

Dominus
Political Access
Joined
2 Mar 2002
Messages
1,572
I am hopelessly lost here.I am playing around with Ajax, but Javascript has stumped me.

Here is my code:

Code:
	<input type="text" name="x" id="x" value="2" size="3" /> * 
	<input type="text" name="y" id="y" value="3" size="3" /> = 

	<!-- This works if uncommented -->
        <!-- <input type="text" name="z" id="z" value="" size="3" /> -->

        <!-- Is this area correct? -->
	<script type="text/javascript">
	xajax_multiply(document.getElementById('x').value,document.getElementById('y').value);
	</script>
        <!-- Is it? -->

	<input type="button" value="Calculate" onclick="xajax_multiply(document.getElementById('x').value,document.getElementById('y').value);return false;" />

That gives me the right output in an input box when this is uncommented:

Code:
<input type="text" name="z" id="z" value="" size="3" />

However, I don't want the output in the textbox, rather just printed out. What changes do I need to make to do this?
 
ok i am about to go out but i thought i would leave this as a helper

you need to look into innerHtml property of a table cell or div element.

theory:

output the result of a calculation to a table cell like so

psuedo code:

document.MyTableCell.innerHtml = (x+y+z)

i hope this gives you enough to go on ...
 
If you just want something to multiply, use

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> 
    <head>
        <title>foo</title> 
        <script type="text/javascript">
 
        function a_multiply(x,y)
        {
           document.getElementById("z").innerHTML=x*y;
        }
 
        </script>
 
    </head> 
    <body> 
        <input type="text" name="x" id="x" value="2" size="3" /> * 
        <input type="text" name="y" id="y" value="3" size="3" /> = 
        <input type="button" value="Calculate" onclick="a_multiply(document.getElementById('x').value,document.getElementById('y').value);return false;" />
 
        <br /><br />
        <div id="z">Sum Goes here</div>
 
 
 
    </body> 
</html>


http://www.albybum.net/temp/osnn4/foo.php
 
Last edited:
I've managed to do it using ajax. It was just a simple Javascript problem. But as you can see, I'm incompetent with Java. Thanks man. Rep++!
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back