Solved

How to tell the difference between textbox and select form field

Posted on 2009-04-15
1
241 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now