How is it possible to put text into a textbox using JavaScript?
-magicyte
Printable View
How is it possible to put text into a textbox using JavaScript?
-magicyte
Adding text to a textbox?! Impossible!
Just joking. It's completely possible, and very easy to do.
Method 1: Using an ID
Method 2: using the form:Code:function add(text){
var TheTextBox = document.getElementById("Mytextbox");
TheTextBox.value = TheTextBox.value + text;
}
Code:function add(text){
var TheTextBox = document.forms[0].elements['field_name']; //I think that's right, haven't done it in a while
TheTextBox.value = TheTextBox.value + text;
}
Here you go magicyte:Code:<script type="text/javascript">
function insertText(val,e){
document.getElementById(e).innerHTML+=val;
}
</script>
<textarea id="textIns"></textarea><br />
<a href="javascript:insertText('Hello ','textIns');" onClick="void(0)">Insert 'Hello'</a><br /><a href="javascript:insertText('GoodBye ','textIns');" onClick="void(0)">Insert 'GoodBye'</a>
Edit: Jas beat me :). I personally thing that my idea is more convenient, though.
Nile: heh. Cross post :)
Magicyte: . . . so what was the point of your post?
I wuz bored and I wanted to see if anyone thought that I was that dumb.
-magicyte
Please don't put up posts like that again. If you have nothing else to do, start a topic in "The Lounge."
EDIT: And in response to your edit of the last post, not knowing that does not make one dumb. There are many beginners that use this website looking for simple answers.
Yeah. I'm sorry. I do think I should be put in Forums Jail.
-magicyte
P.S. {:-(
Sorry if i sound stupid but is it possible to pass a JS variable into the
text value
e.g. var new ="somethign";
<a href="javascript:insertText(' var new ' ,'user_location');" onClick="void(0)">Insert 'Hello'</a>
so when you click it
somethign will be displayed in the box instead of the var new text being displayed
i want to out put the contents of the variable not the name of it
thanks in advance