Extracting Value from Textfields

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
taha
Forum Newbie
Posts: 17
Joined: Tue Nov 22, 2005 2:40 pm

Extracting Value from Textfields

Post by taha »

I have a number of textfields that are named description 1, description 2 ...description 5 and a button named 'Save'. The user needs to input values into each one of these textfields. What I need to do is extract the value of each textfield once the user hits the 'Save' button (function onSave()).

I have the following code, but i can't seem to get anything in my variable string to alert back to me. Could someone please take a look.

Code: Select all

var fieldNames = new makeArray(' description 1 ', 'description 2', ''description 3, 'description 4', 'description 5' ); 

  function makeArray()
  {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
  }

  function onSave()
  {
     var desValues = '';
     for (var i = 0; i<numItems; i++) {
        desValues += document.genericform.elements[fieldDesNames[i]].value + ' ';
        alert(desValues[0]);
     } 
  }
Post Reply