I am going to have several forms, which all use the same class, on a page. They all work the same way. However, I have issues making things work. There is a that needs to update other fields when the user changes the field.
I got this working fine, when there is only one form. However, when i try to have more than one form, it breaks down. I switched from id to class to have the script run, but now I am in situation where jQuery won't give me the ID.
Here is what the HTML looks:
<form class='varaosaTuote' id='lomake0'>
<input type='hidden' value='Add' name='Action' id='Toiminto'>
<table> <tr>
<th> Koko </th>
<th> RTK </th>
<th> Määrä </th>
<th> Hinta/kpl </th>
</tr>
<tr>
<td>
<select class='varaosaKoko' id='valitsin0' name='id'>
<option value='47'>18/450 </option>
<option value='48'>18/600 </option>
<option value='49'>22/450 </option>
<option value='50'>22/600 </option>
</select> </td>
<td> <input id='RTK0' type='text'' name='RTK' value='' readonly> </td>
<td> <input type='text' name='amount' id='maara'> </td>
<td> <p id=hinta><p></td>
<tr></table>
And this is the Jquery:
$(".varaosaKoko").ready( function () {
var id = $(this).attr('id');
var luokka = $(this).attr("class");
//var parent = $(this).closest('form');
console.log("Valmiina kenttä id:" + $(this).attr('id') + ", luokka: " + luokka);
});
Yet, it always gives both id and class as "undefined". In code, as you can see, they are defined.
Anyone have any idea what is wrong? The HTML is generated with PHP, since the plan to have more than one form of the same class, so each one gets their own identifier as a number for id.
EDIT
Clarification, since I forgot this:
The JQuery, in full form and not just the part I posted, is:
$(document).ready(function(){
$(".varaosaKoko").ready( function () {
var id = $(this).attr('id');
var luokka = $(this).attr("class");
//var parent = $(this).closest('form');
console.log("Valmiina kenttä id:" + $(this).attr('id') + ", luokka: " + luokka);
});
});