Psycofishy Posted April 11, 2006 Share Posted April 11, 2006 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 More sharing options...
scott100 Posted April 11, 2006 Share Posted April 11, 2006 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 More sharing options...
raimo Posted April 11, 2006 Share Posted April 11, 2006 (edited) 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... <{POST_SNAPBACK}> 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 April 11, 2006 by raimo Link to comment Share on other sites More sharing options...
Psycofishy Posted April 11, 2006 Author Share Posted April 11, 2006 ok, thankyou. It worked pretty much how i wanted it to (with a bit of fiddling, obviously.) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now