jdubwelch Posted July 30, 2007 Share Posted July 30, 2007 I want one function to be able to change the values into 2 different textareas, by sending the textarea names to the function. but it's not working. function addLink (field) { var url; url = prompt("Enter URL below: ", "http://"); linkTitle = prompt("Enter the link title"); document.form1.field.value = "[url=" + url + "]" + linkTitle + "[/url]"; } <form id="form1" name="form1" method="post" action=""> <p><textarea name="textBox1" cols="45" rows="6"></textarea></p> <p><input name="link" type="button" id="link" value="add link" onclick="addLink('textBox1')" /></p> <p><textarea name="textBox2" cols="45" rows="6"></textarea></p> <p><input name="link" type="button" id="link" value="add link" onclick="addLink('textBox2')" /></p> </form> it doesn't write the values into the boxes, unless i had two different functions that had: document.textBox1.field.value what am i doing wrong? i've looked in my book, and all on the web. Quote Link to comment Share on other sites More sharing options...
Karl33to Posted August 2, 2007 Share Posted August 2, 2007 the problem is to do with the way your referencing the field name, if you run your code you will see an error saying something along the lines of: document.form1.field is null or not an object, which is telling you that the string variable you passed into the function isn't being interpreted as its still called field, if you change it to be referenced like this document.form1[field].value = "[url=" + url + "]" + linkTitle + "[/url]"; it should fix your problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.