View Full Version : Getting values from the input fields

06-11-2008, 09:38 AM
I have a problem of getting values and working with them.
I am trying to generate input fields on the page dynamically using jQuery.
As a result I can generate the array of values for each input field like this:
[input#ends1 34, input#ends2 34]
[input#odds1 343, input#odds2 32]

Then I am trying to get these values with help of for loop and use them in some conditions.
But i am stuck. How can i retrieve each value and put it into the var for futher work? Or my approach is not correct?
The code:

<script language="javascript">
function addFormField() {
var id = document.getElementById("id").value;
$("#divTxt").append("<p id='row" + id + "'><label for='txt" + id + "'>Odds &nbsp;&nbsp;<input type='text' size='20' name='odds[]' id='odds" + id + "'>&nbsp;&nbsp Ends &nbsp;&nbsp;<input type='text' size='20' name='ends[]' id='ends" + id + "'>&nbsp;&nbsp<a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'>Delete</a></label><br/></p>");

id = (id - 1) + 2;
document.getElementById("id").value = id;
function removeFormField(id) {
<script type="text/javascript">
function kvs()
var calc = document.forms['calc'];
var div = document.getElementById('divTxt');
var odds = document.getElementsByName('odds[]');
var ends = document.getElementsByName('ends[]');

for (var i=0;i<ends.length;i++)
var theName = ends[i].value;


<form name="calc">
<p><strong>Odds and ends</strong>:</p>
<p><a href="#" onClick="addFormField(); return false;">Add</a></p>
<input type="hidden" id="id" value="1">
<div id="divTxt"></div>
<input type="reset" value="Reset" name="reset">

<input type="button" name="button" onclick="kvs()" value="Calculate" id="button" />


Thanks in advance!