/    Sign up×
Community /Pin to ProfileBookmark

How to identify the field type in javascript

Hi all,
I am getting all the field name in the form and i am passing the fieldname to the javascript function in order to validate the fields.In the function i am checking each value based on the type.
var a =document.forms[0].fname.value
b=a.split(“,”);
for(i=0;i<a.length;i++) {
type=eval(‘document.forms[0].’+a[i]+’.type’);
if(type==”text”)

alert(“the field type is a text”) //working fine
if(type==”select-one”)
alert(“the field type is select one”) //working fine
if(type==”select-multiple”)
alert(“the field type is select multiple”) //working fine
if(type==”radio”)
alert(“the field type is radio”) //this is not working fine
}

I think for radio type,checkbox i should check as
document.forms[0].radiogroup[0].type

but i don’t how to check with my code
Could anyone say how to check for the field type for radio button or could anyone say how to check if the field type is a single /multiple

Thanks in advance
paula j

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMar 03.2006 — I dont think that you can check if a radio button is a singular or belongs to a group, unless you maybe compared the name value of each, and if they are the same check that one of them is selected. But I don't really understand your question, is English your mother language?
Copy linkTweet thisAlerts:
@sumacasuMar 04.2014 — Hi, I know that this post is a little old as we are in 2014 :-), but I was wondering how can I get the value of a computed text field in java script?
×

Success!

Help @paula_j 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.25,
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,
)...