/    Sign up×
Community /Pin to ProfileBookmark

Extracting value from textfields

I have a number of textfields that are named description 1, description 2 …description x that are created dynamically 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 verifySave()).

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]
var numItems = 1; // Number of Items on page
var fieldDesNames = new makeArray(‘description 1’); // Array of description textfields
var fieldPnoNames = new makeArray(‘partno 1’); // Array of partno textfields

function addNewItem()
{
// Increase the number of items
numItems++;

// Add the rows to the Inner HTML of our TD
document.getElementById(“textfields”).innerHTML += ‘<B><FONT SIZE=2>Item ‘+numItems+’ <BR></B>DescriptionINPUT TYPE=”text” NAME=”description’+numItems+'” VALUE=””> Part Number <INPUT TYPE=”text” NAME=”partno’+numItems+'” VALUE=”” ONKEYDOWN=”if (event.keyCode==9) { addNewItem(); }”><BR>’;
makeArray(‘description’+numItems+”);
makeArray(‘partno’+numItems+”);
}

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

function verifySave()
{
msg = confirm(“Are you sure you want to save this data?”)
if (msg)
{
//submitSave();
var e = document.forms[‘genericform’].elements;
for (var i = 0; i<fieldDesNames.length; i++)
{
alert(e[fieldDesNames[i]].value);
}
}
}

[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@deep_dhyaniDec 02.2005 — code :



<html>

<head>

<Script Language="javascript">

var counter=0;

function add_item(obj){

counter++;

var label='Description_'+counter;

obj=document.getElementById(obj);

obj.innerHTML+=label +": <input type='text' name='txt_fld'>&nbsp;<a href='javascript:remove_item()'>Remove</a><br>"

}

function remove_item(obj){

counter--;

alert('Not Implemented !');

/*

for removing form element *
/

}

function save(){

msg = confirm("Are you sure you want to save this data?")

if (msg)

{


//submitSave();


var e = document.forms['frm'].txt_fld;

for (var i = 0; i<e.length; i++)

{

alert(e[i].value);

}

}



}

//add_item("f1");

</script>

<Body>

<center><b>

<a href="javascript:add_item('f1')">Add Text Field </a><br>

</center>

<form id='frm' name='frm' action='' method='post' onsubmit='return save()'>

<div id='f1' name='f1'>

</div>

<br>

<input type='submit' value=" Save ">

</form>

</BOdy>

</Html>

[/QUOTE]
×

Success!

Help @toots spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...