Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Thanked 0 Times in 0 Posts

    Getting values from the input fields

    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!
    Last edited by Kor; 06-11-2008 at 12:13 PM. Reason: wrap the code [code][/code]


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts