Results 1 to 3 of 3

Thread: javascript, Auto insert into input/textarea

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    119

    javascript, Auto insert into input/textarea

    Code:
    <html>
    	<head>
    		<script type="text/javascript">
    			function writeStuff(theform, theinput, code)
    			{
    				  var cache = document.theform.theinput.value;
    				  document.theform.theinput.value = cache + " " + code + " ";
    				  document.theform.theinput.focus();
    			}
    		</script>
    	</head>
    	<body>
    		<form name="sform" method="post" action="">
    		<textarea name="message" cols="15" rows="15"></textarea><br /><br />
    		<input type="button" onClick="writeStuff('sform','message','STRING HERE');" name="" />
    		</form>
    	</body>
    </html>
    My problem when I click the button, it doesnt add 'STRING HERE' to the textarea, this function worked perfectly before I attempted to make it universal with some arguments like theform and theinput, can anyone give me a hint on whats wrong.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: javascript, Auto insert into input/textarea

    I think:
    Code:
    var cache = document.forms[theform].elements[theinput].value;

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    119

    Re: javascript, Auto insert into input/textarea

    no, still cant get it to work

    Code:
    <img onClick="writeStuff(\'eshoutbox\',\'shoutm\',\':sad\')" src="images/smileys/sad.gif" />

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width