java - How to get several buttons' text at once in Javascript? -
i have following code, it's part of java servlet, html, javascript/jquery web app.
<table border=1> <tr> <td><button id=current_1 type=button></button></td> <td><button id=current_2 type=button></button></td> <td><button id=current_3 type=button></button></td> <td><button id=current_4 type=button></button></td> <td><button id=current_5 type=button></button></td> <td><button id=current_6 type=button></button></td> </tr> </table>
what can on java servlet side text in each of buttons, i'm thinking having submit button when it's clicked, jquery gets buttons , loop through them each button's text.
the text in buttons have nothing, during app user can click , change values, @ end need give user way save content on buttons , pass them servlet, what's best way achieve that, sample code ? need how hold of buttons , loop through them text ?
edit : maybe didn't express clearly.
if button_1 has text "b1" button_2 has text "b2" ... button_6 has text "b6"
the result expect after user click submit button : b1b2b3b4b5b6
fairly simple make array of objects using jquery
var buttondata = $('button[id^="current"]').map(function(){ return {id: this.id, text: $(this).text()}; }).get();
produces:
[ {id:"current_1", text: "button #1 text"}, {id:"current_2", text: "button #2 text"}, .... {id:"current_6", text: "button #6 text"} ]
a class selector cleaner or target them selector on row
edit: if want combined text no delimiters can whole collection of text without looping elements.
$('button[id^="current"]').text();
for value getters in jquery approach return vlue of first element text()
returns all
Comments
Post a Comment