[Javascript] Printing out (?)

Discussion in 'Web Design & Coding' started by vern, Aug 13, 2005.

  1. vern

    vern Dominus Political User Folding Team

    Messages:
    1,571
    Location:
    Minnesota, USA
    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?
     
  2. Mooz

    Mooz Moozically Con~foozed

    Messages:
    126
    Location:
    UK
    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 ...
     
  3. albybum

    albybum Penguin Rancher

    Messages:
    280
    Location:
    Elizabethton, TN
    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: Mar 23, 2007
    vern likes this.
  4. vern

    vern Dominus Political User Folding Team

    Messages:
    1,571
    Location:
    Minnesota, USA
    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++!