views:

184

answers:

3

How would I change the below to jquery? It works in IE but not Firefox so I am hoping if I change it to jquery it will work for both.

THIS

function subform() {
 if (parent.option_view.document.vform_.dispatchEvent('onsubmit') != false) {
  parent.option_view.document.vform_.submit();
 }
}

AND THIS

img class="save_bttn" src="/images/save.gif" height="16" width="16" border="0" onclick="subform()"

IS INSIDE ONE CHILD FRAME

and

It is trying to init in another child frame that is why its going to parent option_view.

*note: I was not trying to scream with the caps I was just trying to show where talking was and where the javascript is

A: 

Maybe:

$("#vform_").submit();

?

Kip
does it work on parent? maybe $(parent).child("#vform_").submit() ?
elcuco
A: 

fireEvent is a IE only feature. I don't think including JQuery just to fix this is the best solution. (why add more download time/process time if you can avoid it). Switch to using The W3C equivalent: dispatchEvent. Take a look at http://www.howtocreate.co.uk/tutorials/javascript/domevents on how to use EventListener...

Mohammad
A: 

There are two ways I would suggest you do this, the first with jquery, the second without:

$('.save_bttn').bind('click', function(e) {
if (parent.option_view.document.vform_.dispatchEvent('onsubmit') != false) {
  parent.option_view.document.vform_.submit();
 }
});

The other is:

<img class="save_bttn" id='somebutton' ... />
document.getElementById('somebutton').onclick = function(e) {
  // if(...)
}

I would think that your using this subform() function means that there is something flawed in your approach. I am not certain why you have needed dispatchEvent, as you could have just submitted directly from the onclick event handler, but these should work, or, at least, be close enough so that someone here can correct me. :)

James Black
I tried this but got this erroruncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMEventTarget.dispatchEvent]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: {path2file}bar.php?locationid=1 :: anonymous :: line 11" data: no]
David
If you are sending JSON data to the server on clicking submit then you need to make certain that you are sending {"key":"value"} for objects. The quotes around the key, and generally, around the value is important. But, it sounds like you got it working, based on your comment.
James Black