/    Sign up×
Community /Pin to ProfileBookmark

Separate TEXTAREA from INPUT using javascript

I want to separate textarea from input in my HTML form! I have done it but it’s ugly and slow and not useful. I want to do one loop through my whole form and separate one from the other so I can specify how to pull the value. The form is PHP and very dynamic so I don’t know the names of the fields. Can someone please assist me in doing one loop so I can get over this big issue.? Here is my code!

[CODE]var arr = new Array();
arr = document.getElementsByTagName( “TEXTAREA” );
var params =””;
for(var i=0; i < arr.length; i++)
{
var tagName = document.getElementsByTagName( “TEXTAREA” ).item(i).name;
var elValue=CKEDITOR.instances[tagName].getData();

params = params + tagName+”=”+elValue+”&”;
}

arr = document.getElementsByTagName( “INPUT” );
var params2 =””;
for(var i=0; i < arr.length; i++)
{
var tagName = document.getElementsByTagName( “INPUT” ).item(i).name;

var tagObj = document.getElementsByTagName( “INPUT” ).item(i).value;
params2 = params2 +tagName+”=”+tagObj+”&”;
}[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 19.2010 — Get all elements in the form, then in the loop check the nodeName for textarea or input and branch accordingly.
×

Success!

Help @blackbad88 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...