tags:

views:

41

answers:

1

I have to add an input with a name of "btnupdateprice" that I first have to dynamically insert it into the page (hidden of course) and then trigger it. Is there a way to do this without inserting it into the page like the following? A shortcut perhaps?

$("input[type='hidden'][name='ProductCode']").before('<input type="image" border="0" name="btnupdateprice" src="blank_image.gif" style="display: none;">');
$('input[name=btnupdateprice]').trigger('click');
+2  A: 

You could try the reverse flow using insertBefore, and the shorthand function click

$('<input type="image" border="0" name="btnupdateprice" src="blank_image.gif" style="display: none;">').insertBefore("input[type='hidden'][name='ProductCode']").click();

If you don't want to add it to the page you can just remove the .insertBefore(...) part.

Dan Manastireanu
Not exactly what I was looking for, not that your are wrong cause you are not, but I was hoping for a way to do that without actually inserting a input element. Even if it was only for a instant between when its inserted and then triggered. Perhaps its not possible.
Maybe you can clarify why exactly you can't call directly the `form.submit()` function ? (ex: `$('form')[0].submit()`)
Dan Manastireanu
Although this does not answer my question exactly it does provide a partial answer to my question (shortcut) so I will have to give this one to you. Thx
@Dan cause there is another input button in the form.