• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[Javascript] Printing out (?)

vern

Dominus
Political User
#1
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?
 

Mooz

Moozically Con~foozed
#2
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 ...
 

albybum

Penguin Rancher
#3
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:

vern

Dominus
Political User
#4
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,016
Latest member
ernestrojasn