why won't this work? (simple script of "printing" text the was inserted by the user)

Discussion in 'JavaScript' started by zoobooboozoo, Jan 13, 2007.

  1. #1
    I want to write using javascript the number entered in "tempo"...

    
    <html>
    head
    	<title>
    	Welcome to TempoToTime  convertor!
    	</title>
    
    	<script language="javascript">
    	function calc()
    	{
    	var tempval = document['tempo'].value;
    	document.write(tempval);
    	}
    	</script>
    </head>
    <body>
    
    Tempo value: <input type="text" name="tempo"><br>
    Notation: <input type="text" name="note"><br>
    <button type="button" onClick="javascript:calc();">Calculate!</button>
    
    </body>
    </html>
    
    Code (markup):

     
    zoobooboozoo, Jan 13, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <html>
    <head>
    	<title>
    	Welcome to TempoToTime  convertor!
    	</title>
    
    	<script language="javascript">
    	function calc()
    	{
    	var tempval = document.getElementById('tempo').value;
    	document.getElementById('res').innerHTML = tempval;
    	}
    	</script>
    </head>
    <body>
    Tempo value: <input type="text" name="tempo" id="tempo"><br>
    Notation: <input type="text" name="note" id="note"><br>
    <input type="button" onClick="javascript:calc();" value="Calculate!">
    <br />
    <span id="res"></span>
    </body>
    </html>
    HTML:
     
    krakjoe, Jan 13, 2007 IP
  3. zoobooboozoo

    zoobooboozoo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Gee, sorry, forgot to point out what wasn't working!
    how stupid of me...

    anyway, the problem was that it didn't print the tempo.value ! (regardless of where printed and how)...

    even with the <div> etc. it doesn't work,
    when I tried to fix a value for tempval in the function it worked:
    
    var tempval = 12;
    
    Code (markup):
    something with getting the value is wrong...
     
    zoobooboozoo, Jan 13, 2007 IP
  4. zoobooboozoo

    zoobooboozoo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    nvm, thanks a lot for the help!
    I got it now!
     
    zoobooboozoo, Jan 13, 2007 IP