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. Link to comment https://forums.phpfreaks.com/topic/62396-one-function-to-change-two-textboxes-not-working/ 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 Link to comment https://forums.phpfreaks.com/topic/62396-one-function-to-change-two-textboxes-not-working/#findComment-314396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.