I have a form that is dynamically generated, and has dynamically generated id\'s (and potentially classes). The forms are the same but they have the related id tacked on to
I don't think you should be using the @ sign and you're missing some quotes:
Instead of this: $('input[id^=@id_airline_for_]')
try this: $("input[id^='id_airline_for_']")
See this, too:
http://docs.jquery.com/Selectors/attributeStartsWith#attributevalue
$("input[id^='id_airline_for_']").each(function() {
var id = parseInt(this.id.replace("id_airline_for_", ""), 10);
var airline = $("#id_airline_for_" + id);
var flightNumber = $("#id_flight_number_for_" + id);
// do stuff with airline and flightNumber <input>s
});
The following will get you all of the inputs that contain id_airline_for
in their name.
$("input[id^='id_airline_for']")
If you need to do this on a per form basis, you'll want to give each form its own ID and select them in groups that way.
$("#formJetBlue input[id^='id_airline_for']")
$("#formNwa input[id^='id_airline_for']")
$("#formOceanic input[id^='id_airline_for']")
Selects elements that have the specified attribute with a value containing the a given substring
$('input[id *= id_airline_for]').attr('checked', headerChecked);
it will select all elements that contain 'id_airline_for' string in the 'id' attribute
You can use $("input#id_airline_for" + id)
(where id
is your number, e.g., 8), but it will be faster if you drop the tag name and just use:
$("#id_airline_for" + id);