0

I have an iframe that contains several div and other elements. I would like set focus to one of the textbox out of several textboxes.

I used:

    a = iFrameObj.contentWindow.document.getElementById('myTxtBox');

   But here, a is null;

I am able to get access to the textbox object using following code;

var myTextBox = iFrameObj.contentWindow.document.getElementsByTagName('input')[52];

But I would like to use more generic method to obtain object rather than hardcoding the index.

Since this textbox has unique class name, I tried following code:

var myTextBox = iFrameObj.contentWindow.document.getElementsByClassName('rgtxt')[0];

but i error:

"Object does not support this property or method"

HTML for my textbox is:

<input name="myTxtBox" type="text" class="rgtxt" id="myTxtBox" value="hello" style="display:block;color:Black;background-color:rgb(240, 241, 241);" readonly="readonly" />

Can somebody help what is the difference between these two methods in iFrame ?

Rohita Khatiwada
  • 2,835
  • 9
  • 40
  • 52

3 Answers3

0

Check this

$("input[id$='myTxtBox']").val()
0

try this

 $("#youriFrameID").contents().find("input.rgtxt").focus();

using jquery...

bipen
  • 36,319
  • 9
  • 49
  • 62
0

The getElementsByClassName method is only available on IE9+, so the error message is correct (although not that clear), there is no such method on IE8.

You can read more about it here: http://msdn.microsoft.com/en-us/library/ie/ff975198(v=vs.85).aspx

Francisco Paulo
  • 6,284
  • 26
  • 25