passing variable into getElementById

Results 1 to 2 of 2

Thread: passing variable into getElementById

  1. #1
    Join Date
    Dec 1969

    Default passing variable into getElementById

    I have a javascript function below that I can&#039;t seem to get to work. What I&#039;m trying to do is pass the fieldname variable into the getElementByID so that I can populate the correct &#060;span&#062; on the calling page.<BR><BR>The error I believe is on this line, but I&#039;m not sure what the correct syntax is. <BR><BR>window.opener.document.getElementById(fldN ame).innerHTML = Note;<BR><BR>Any help is appreciated.<BR><BR>function GetData(ab)<BR>{ <BR>var blahID = &#039;&#060;%=blahID%&#062;&#039;;<BR> var fldName = "content1"+blahID;<BR> <BR> alert(&#039;fldName &#039; + fldName);<BR> var wDoc = window.opener.document;<BR> var eDiv = document.all ? wDoc.all[fldName] : wDoc.getElementById(fldName);<BR> window.opener.document.forms.form1[fldName].value= ab;<BR>window.opener.document.getElementById(fldNa me).innerHTML = ab;<BR><BR> <BR> window.close();<BR>}

  2. #2
    Join Date
    Dec 1969

    Default Looks okay to me in fundamentals...

    ...except that you use that<BR> document.all ?<BR>stuff. Why? That&#039;s telling the system to use document.all in MSIE (because MSIE is the only browser that supports "all"), but getElementById() has been valid in MSIE since at least version 5 and I think since version 4. The ".all" trick is kind of ancient history.<BR><BR>If you *must* use that kind of trick, do it the other way around:<BR> var eDiv = wDoc.getElementById ? wDoc.getElementById(fldName) : wDoc.all[fldName];<BR><BR>But now explain to me: How can it be valid to put the same thing into the contents of some text (? or TextArea?? hmmm...that might make more sense) field as you do into some HTML element? And you have this HTML element with an ID that is the same as the name of the form field???<BR><BR>That is, you have<BR> &#060;SPAN ID="content1XYZ"&#062;&#060;/SPAN&#062;<BR>as well as<BR> &#060;FORM Name=form1&#062;<BR> &#060;TEXTAREA Name="content1XYZ"&#062;&#060;/TEXTAREA&#062;<BR>???<BR><BR>It does seem kind of curious to me that the popup window will know the ID of a field in the caller window by means of a server side value. But if your alert(fldName) shows the right ID...&#060;shrug&#062;Should work.&#060;/shrug&#062;<BR><BR>

Posting Permissions

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