I build a table dynamically in js where each row has same elements
- input | input | **select** | **text** | **text** | **select**
Event 1 - input | input | **select** | **text** | **text** | **select**
- input | input | **select** | **text** | **text** | **select**
Event 2 ... ... .... ... ... ...
...
Event 10 ... ... .... ... ... ...
As you can see the select has a class="place" for all 3 'td's When I select a value I want it to update just the NEXT text and not all the text elements.
$("select.place").change(function () {
$('.place').parent('td').next('#score').text("val")
});
This is updating all the text fileds with the val
I am generating the rows like this and appending them to a table :
'<td> ' +
'<select class="place"> ' +
'<option value="1">1</option> ' +
'<option value="2">2</option>' +
'<option value="3">3</option>' +
'</select>' +
'</td>' +
'<td id="score"></td>' +
'<td id="score"></td>' +
'<td>' +
'<select class="place"> ' +
'<option value="1">1</option>' +
'<option value="2">2</option>' +
'<option value="3">3</option>' +
'</select>'
As you can see, I am not setting id's only class
I am not sure what the best way is to set the value after "select" and then conversely set the value before the second "select" per row.
Any help/ideas would be most welcomed.
Code for select change:
$("select.place").change(function () {
switch (parseInt($('select.place').val())) {
case 1:
$(this).parent('td').next('#score').text("10");
break;
case 2:
$(this).parent('td').next('#score').text("8");
break;
case 3:
$(this).parent('td').next('#score').text("6");
break;
default:
$('select.place').val() == "0"
}
});
CODE to loop through table to get values from objects
$("input:button").click(function () {
var values;
values = "";
$("table tr").each(function () {
$(this).find("td").filter(':visible').each(function (index) {
if(index =5)
{
if ($(this).find("text").val() != undefined)
values += $(this).find("text").val() + ";";
if ($(this).find("label").text() != undefined)
values += $(this).find("label").text() + ";";
if ($(this).find("input").text() != undefined)
values += $(this).find("input").text() + ";";
if ($(this).find("select option:selected").text() != "")
values += $(this).find("select option:selected").text() + ";";
}
});
});
values = values.replace(/\;;/g, ";");
console.log(values)
});