How can i simulate a click of the button below? I tried using the javascript
$("#Save").click()
but it didnt work. Does this have to do with it not working because there is no id but name?
<input class="button" type="submit" name="Save" value="Save" onclick="OnSubmit(this.form);">
What javascript mand in my browser would i use to simulate the click of Save following something like i tried to use?
Much help appreciated! Im new to this
How can i simulate a click of the button below? I tried using the javascript
$("#Save").click()
but it didnt work. Does this have to do with it not working because there is no id but name?
<input class="button" type="submit" name="Save" value="Save" onclick="OnSubmit(this.form);">
What javascript mand in my browser would i use to simulate the click of Save following something like i tried to use?
Much help appreciated! Im new to this
Share Improve this question edited Sep 6, 2013 at 15:08 OneOfOne 99.6k22 gold badges192 silver badges187 bronze badges asked Sep 6, 2013 at 15:06 soniccoolsoniccool 6,06823 gold badges64 silver badges101 bronze badges 1-
1
You need the
id="Save"
because the#
sign in your JQuery selector means it is selecting the ID following it (Save in your case). – Tricky12 Commented Sep 6, 2013 at 15:08
3 Answers
Reset to default 8It appears your using jQuery with an id selector (#
denotes an id), however the element doesn't have an id. Since the element does have a name attribute, an attribute selector can be used by jQuery. An appropriate selector would be:
$('input[name="Save"]').click(); //Assuming no other elements have name=Save
JS Fiddle: http://jsfiddle/pJD3R/
You could also change the markup to work with your existing selector by adding an id
attribute:
<input id="Save" class="button" type="submit" name="Save" value="Save" onclick="OnSubmit(this.form);">
$("#Save").click()
mean you target an element with the id save
but you don't have any id on your input.
<input class="button" id="save" type="submit" name="Save" value="Save" onclick="OnSubmit(this.form);">
$('input[name=Save]').click(function(){
alert('Do Something');
});