Solved

How to tell the difference between textbox and select form field

Posted on 2009-04-15
1
244 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
1 Comment
 
LVL 42

Accepted Solution

by:
David S. earned 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

726 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