?
Solved

How to tell the difference between textbox and select form field

Posted on 2009-04-15
1
Medium Priority
?
247 Views
Last Modified: 2012-05-06
Is there a way that I can determine what type of form field a given form element is?

I would like to do this:

if (form_name.variable_name.type == 'select') {
 alert ('select')
}
elseif (form_name.variable_name.type == 'textbox') {
 alert ('textbox')
}
0
Comment
Question by:djlurch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 42

Accepted Solution

by:
David S. earned 2000 total points
ID: 24146073
The type for a (single line) textbox is "text". A <select> element has a type of "select-one" or "select-multiple".
var control = document.forms[form_name].elements[variable_name];
 
if (control.type.indexOf('select')!=-1) {
 alert ('select');
}
else if (control.type == 'text') {
 alert ('textbox');
}

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question