1

I am trying to use a single function to execute a simple job. This function will import a small text in a textarea.

This part is done but when I am using variables for form name and textarea id, I cannot import the form name and the id of the textarea.

This is the function

<script language="javascript" type="text/javascript">
 function addtext_(x,y) {
  var formID = "newQuote_" + y;
  var messageID = "messageText_" + y;

  //alert(formID);
  document.[formID].[messageID].value += x;
 }
</script>

If I have the alert function on, I can see the generated vars but cannot import them in the following line document.[formID].[messageID].value += x;

Thank you.

1 Answers1

1

If you are already using bracket notation, then dot . is not requried.

document.[formID].[messageID].value += x;

should be

document[formID][messageID].value += x;

But in your case, if messageID is the id attribute of element, then use this

document.getElementById(messageID).value += x;
gurvinder372
  • 66,980
  • 10
  • 72
  • 94