I am new to javascript and html and I have a question
In order to test that a submit button works correctly I used this jquery script
$(document).ready(function() {
$("#search_form").submit(function() {
alert("you pressed submit");
event.preventDefault();
return false;
});
});
This works as expected, when I press the submit button it pops up a message
However when I use the following code (which in theory does the same thing)
$(document).ready(
set_up_listeners()
);
function set_up_listeners() {
$("#search_form").submit(submit_pressed());
};
function submit_pressed() {
alert("you pressed submit");
event.preventDefault();
return false;
};
the alert pops up when the document is ready, not when I press submit What am I doing wrong? I like the second type of code cause it is easier for me to read, but I can't figure out why it does not work
Thanks in advance for any help you can provide