Aditya
Aditya

Reputation: 75

Picking value from Text Box in jquery by ID

I am having 3 textbox where the ids are

"ctl00_m_g_8b41d68e_7c2d_49c3_a4b5_316440ad77e1_SpListPicker_SelectionBox", "ctl00_m_g_9b41d68e_7c2d_49c3_a4b5_316440ad77e1_SpListPicker_SelectionBox" and "ctl00_m_g_8a41d68e_7c2d_49c3_a4b5_316440ad77e1_SpListPicker_SelectionBox".

Now the id which is getting generated dynamically, but the "SpListPicker_SelectionBox" is constant. Now I am having a requirement, onClick of a button either of the 3 textbox will have the value, which is to be fetched. How can I get the value of textbox. Any help is appreciated. Can we get the value on the like operator? where ID like '%SpListPicker_SelectionBox' ??

Upvotes: 0

Views: 269

Answers (3)

palaѕн
palaѕн

Reputation: 73916

Try this:

var $inputs = $('input[id$="SpListPicker_SelectionBox"]')

Where $= is the Attribute Ends With Selector

Then you can loop through each textbox and get the values like:

$inputs.each(function( index ) {
  alert( index + ": " + $(this).val() );
});

Upvotes: 1

Gaurav Agrawal
Gaurav Agrawal

Reputation: 4431

you can write Javascript or jquery code runtime by using code while textboxs generated and use exact textbox id associate with jquery statement.

Upvotes: 0

bipen
bipen

Reputation: 36531

use attribute selector with $ ,this fetch all the elements ending with the given string..

docs

 $('input[id$="SpListPicker_SelectionBox"]').val()

Upvotes: 0

Related Questions