Jump to content

dont know..


Psycofishy

Recommended Posts

knowing me its probably the most obvious thing in the world...how can i have it so there is a form in html... and what you type in becomes the value of a variable in javascript.This would be for... an example:you type in your name and this can be re written elsewhere on the page within a sentence.if you get me... :)

Link to comment
Share on other sites

saves the value of the textbox in a javascript variablewrites the variable in a sentance. :)

<head><script>function update(){ var Name=document.getElementById('box').value; document.getElementById('name').innerHTML=Name;}</script></head><body><form><input type="textbox" id="box" /><input type="button" value="update" onclick="update()" /></form><p>Hello <span id="name"></span>, i am a sentance</p><body>

Link to comment
Share on other sites

knowing me its probably the most obvious thing in the world...how can i have it so there is a form in html... and what you type in becomes the value of a variable in javascript.This would be for... an example:you type in your name and this can be re written elsewhere on the page within a sentence.if you get me...  :blink:

Play some time with these examples :)
<script type="text/javascript"><!--function addName(elm, elm2){document.getElementById(elm).innerHTML =  document.getElementById(elm2).value;}//-></script><div id="d1"></div>Name:<input id="txt1" type="text"><button onclick="addName('d1', 'txt1')">Push me!</button>

each pressed key from text-input to the div:

<script type="text/javascript"><!--function copyKeys(e){var element = document.getElementById('d1'); var key = (e.which) ? e.which : event.keyCode; var chr = String.fromCharCode(key);element.innerHTML = element.innerHTML + chr;}//--></script><div id="d1"><!-- text will come here like a ghost --></div><input type="text" onkeypress="copyKeys(event)">

edit: scott was faster :) ( but I have keys too :) )edit2: fixed .. something

Edited by raimo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...