I have a table something like this
<table>
<tr>
<td></td>
<td>
<select>
<option>One</option>
<option>Two</option>
</select>
<button class="makeStrng">+</button>
</td>
<td>
<input type="text" />
</td>
</tr>
<tr>
<td>
<button class="addRow">Add ME</button>
</td>
</tr>
</table>
I am trying to get the text of selected item and add it to the input box. And if I click on the plus(+) again it should add the string again in the select box with a space.
For example if I select TWO first and clicked on the add button in text box it should show two then again if I select ONE it should show TWO ONE in the text box.
I can't use ID here because I am giving the user option to add this row many number of times.
SCRIPT
$(document).ready(function () {
$(document).on("click", ".addRow,.makeStrng", function () {
var $class = $(this).attr("class");
if ($class == "addRow") {
var $row = $(this).closest("tr"); // Finds the closest row <tr>
var prev = $row.prev();
$(prev).after("<tr>" + prev.html() + "</tr>");
}
if ($class == "makeStrng") {
//alert("MakeStrng");
$class = $(this).closest("select");
alert($($class + " option:selected").text());
}
});
});
Thanks in advance