I have written some code in Jquery that when a button is pressed, creates a new variable and displays it on the screen. I'd like to take whatever data is entered into this new variable and store it in a database however before I get there I have to figure out to access the variables information properly.
In HTML I have 3 text boxes created and a button to add up to 7 more for a total of 10. My code looks like this (and these store in the database just fine):
<table style="width:90%" class="Long-Term-Conditions">
<center>
<tr>
<td><b><center>Long term condition 1:</center></b></td>
<td><center><input type='text' id="Var1" name ='Var1' value='%Var1%' /></center></td>
</tr>
<tr>
<td><b><center>Long term condition 2:</center></b></td>
<td><center><input type='text' id="Var2" name ='Var2' value='%Var2%' /></center></td>
</tr>
<tr>
<td><b><center>Long term condition 3:</center></b></td>
<td><center><input type='text' id="Var3" name ='Var3' value='%Var3%' /></center></td>
</tr>
</center>
</table>
<a href="#" title="" class="add-cond" id="add-cond">Add another long-term health condition</a>
<div id="Message"></div>
My problem now is that my Jquery variables cant be inspected (says not available) and no data is passed to the database after. My Jquery looks like this:
<script>
//Adds another row to the above table.
var counter = 3;
jQuery('a.add-cond').click(function(event){
event.preventDefault();
if (counter < 10) {
counter++;
var newRow = jQuery('<tr><td><b><center>'+ "Long term condition "+ counter + ":" + '</center></td> <td><center><input type="text" name="Var' +
counter + '" id="Var' + counter + 'value="%Var' + counter + '%"/></center></b></td></tr>');
jQuery('table.Long-Term-Conditions').append(newRow);
}
else
{
document.getElementById("add-cond").style.visibility = "hidden";
document.getElementById("Message").innerHTML = '<font color="Red">Please
contact us</font>';
}
});
</script>
The code works in creating the new variable however any data entered into the newly created text box is never passed to the debugger or the database. What am I doing wrong? Any help is appreciated.