I have a webpage where there are several forms. It looks like
.
When “Create” is clicked an ajax script checks the fields for illegal values in the first form, where the Create button belongs to. That’s fine.
But when the “Save” button is clicked, it still checks fields from the first form, and not the form where the Save button belongs to.
My Ajax looks like this
$(document).ready(function(){
// $('form').submit(function() {
$('form').live('submit', function(){
var title = $('#title').val();
...
Is it here the problem could be? I have tried with the commented code, but that doesn’t work either.
Any ideas where the problem could be?
$('#title').val();means “Get the value of the one and only input that has the id title“.If you have violated the spec and have multiple elements with the same id, then browsers will generally recover from the error by returning the first such element.
You should probably change the id to something like: idOfForm_title (so that your
<label>elements still work)And then use:
this.elements.title.valuewheretitleis the value of the name attribute (andthisautomatically resolves to the form on which the submit event fires).