1

I am calling a Javascript function located in my parent window from an Iframe located in the parent during an onkeyup event. IE complains and the debugger built into IE8 stops and highlights the 'if block' within this code saying - "Object doesn't support this kind of property or method"

PS - This bit of code works in FF!

     <td class="grid" align="left">
     <input type="text" name="invqty${topitem.itemIdentifier}-<c:out value = "1"/>"
        id="invqty${topitem.itemIdentifier}-<c:out value = "1"/>" 
        value="0" 
        onFocus="this.select()" 
        onkeyup="if(!parent.validateFloat(this.id)) { this.value = '0'; } 
                 else { parent.updateBalance(${topitem.itemIdentifier}); }">
     </td>

Anyone have any ideas?

ivan_drago
  • 547
  • 1
  • 7
  • 29
  • Can you create a javascript function, say `doKeyUp(thisElement, itemIdentifier)`, put the following in the function: `if(!parent.validateFloat(thisElement.id)) { thisElement.value = '0'; } else { parent.updateBalance(itemIdentifier); }` and use the function in `onkeyup`? Like `onkeyup = "doKeyUp(this, ${topitem.itemIdentifier})"` Now if you use the debugger, you may get the exact line where this is failing. – Nivas Aug 03 '12 at 18:13
  • @Nivas - the debugger highlights "if(!parent.validateFloat(this.id))" - I know that it doesn't like this bit of code. Or are you saying that the problem could be elsewhere? – ivan_drago Aug 03 '12 at 18:18
  • do you have a `validateFloat` function defined? – Nivas Aug 03 '12 at 18:19
  • Yes - I'll add it above if you think it will help you. – ivan_drago Aug 03 '12 at 18:20
  • @Bergi - parent is the main page where my iframe resides. I am calling this onkeyup event from my iFrame. They are on the same domain btw. This is working in FF, so this is something specific to IE I believe. – ivan_drago Aug 03 '12 at 18:22
  • @ivan_drago `Object doesn't support ` generally occurs when something you try to access (a property or method) does not exist. So if you get the error in `parent.validateFloat` this means that `validateFloat` does not exist in `parent`. IE is sometimes notorious in error message reporting. I wanted to see whether the method itself exists. BTW, same as @Bergi's question: what is `parent`? – Nivas Aug 03 '12 at 18:24
  • OK, I missed that. Try to step through the code by resolving the references each on their own, i.e `window.parent`, then `.validateFloat`, then `this.id`, then invoke it... – Bergi Aug 03 '12 at 18:25
  • @Nivas, Bergi - I think both of you are onto something. I'll follow up shortly after moving stuff around and inspecting the location of my functions and whether they "exist" in the eyes of Internet Explorer. – ivan_drago Aug 03 '12 at 18:46
  • @Bergi - I tried moving my JS into the iFrame itself but it is as if IE is ignoring it completely! I don't understand why even though the code exists and I explicitly tell IE to load it, it still ignores it! WTF! I hate IE. – ivan_drago Aug 03 '12 at 19:06

3 Answers3

0

You have invalid characters in your name attribute. Read here for further on valid characters.

Community
  • 1
  • 1
Robin Maben
  • 19,662
  • 16
  • 61
  • 93
  • The name attribute resolves to an alphanumeric string with a hyphen character (which is allowed) - i.e. "invqty12345-1" I don't think that is the issue. – ivan_drago Aug 03 '12 at 18:11
0

Are you running this setup locally as in from "file://"? That won't work. IE has a very strict security model on iframe communications for files run locally. You'll need to run it through a web server.

sapel
  • 81
  • 1
  • 2
0

Wow!!! So the issue was this -

I had about 5 functions that I was defining within my iframe. They all were happening within a single 'script block'

One of these functions was using a "for each" loop. This one loop in one of those 5 functions caused IE to IGNORE the entire 'script block' where I was doing this. The kicker was that the debugger within IE8 was telling me the problem was on some bogus line number where it made me think that there was an issue with my iframe and how I was trying to define my JS functions. Finally, I gave up and went and asked somebody with a MAC to debug this using Safari. The Safari debugger nailed down the exact line with the for each loop. I commented that for each loop code out and IE started working too!

Unbelievable!

The developers for the IE8 Browser Debugger should be beaten over their wrists with a yard stick for their incompetence. I wasted 3 days on this. Kudos for the peeps at Apple.

Lessons learned here -

DON'T use "for each" loops when writing Javascript! DON'T use Microsoft IE branded debuggers! They are terrible and will waste your time.

Thank you for your help Bergi and Nivas!

ivan_drago
  • 547
  • 1
  • 7
  • 29