Reputation: 597
On the press of the button, i want to alert the two values in the two inputs. However, this is not working, the page just redirects to the main page in jquery mobile.
JS
$('newann').submit( function () {
alert($('#t').val());
alert($('#m').val());
});
HTML
<form id="newann" name="newann">
<input type="text" id="t" placeholder="Title" />
<input type="text" id="m" placeholder="Add more..." />
<button type="submit" name="submit">Publish News</button>
</form>
Upvotes: 0
Views: 1030
Reputation: 6544
Your selector is wrong. It should be $('#newann') as "newann" is id of the form.
You should use .(dot) for class selector and #(hash) for id selector.
Upvotes: 2
Reputation: 121998
Selector syntax incorrect.You forgot to add #
(Assuming selecting id
)
$('#newann').submit( function () {
alert($('#t').val());
alert($('#m').val());
});
Upvotes: 2