jQuery selection with dynamic id’s

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 the end.

How can I select each set of inputs and apply code to each one?

I was experimenting with $(‘input[id^=@id_airline_for_]’) but could not get it to fly. I suspect I am missing some fundamental jQuery knowledge that is holding me back since I am sure this is a common problem with dynamic forms.

<form method='POST'>
    <label for="id_airline_for_8">Airline</label>:
    <input id="id_airline_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="airline_for_8"/>
    <label for="id_flight_number_for_8">Flight Number</label>:
    <input id="id_flight_number_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="flight_number_for_8"/>

    <label for="id_airline_for_17">Airline</label>:
    <input id="id_airline_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="airline_for_17"/>
    <label for="id_flight_number_for_17">Flight Number</label>:
    <input id="id_flight_number_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="flight_number_for_17"/>

    -- snip --


EDIT: I should update that i want to be able to perform some action when the input is clicked but only for classes with a matching id at the end.

To make it easy, lets say I want all inputs with a matching id at the end of the #id to disappear when one is clicked (just for arguments sake).


$("input[id^='id_airline_for_']").each(function() {
  var id = parseInt("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

Can Java Enumerations be merged (like Bitwise in C#)?

Is there a way in Java to declare an enumeration whose values can be used together? For example:

enum FileAccess { Read, Write, ReadWrite }

Is it possible to define ReadWrite as Read | Write (or anything that would yield the same result)?


You use EnumSet:

EnumSet<FileAccess> readWrite = EnumSet.of(FileAccess.Read, FileAccess.Write);

This is actually somewhat more elegant than the C#/.NET way, IMO – aside from anything else, you can easily distinguish between a set and a single value.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..