This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Using One Input for Multiple Functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using One Input for Multiple Functions" Watch "Using One Input for Multiple Functions" New topic
Author

Using One Input for Multiple Functions

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1391
In a queue filter frgment I have several option buttons. Depending on which button is selected an input box appears. In some cases it is simply to type in text, in a couple is presents a drop down list. I display the various input options by using div tags, inline or none. What I want to know is if and how to use the same name for the input controls so in my js I am having to look at the value of one tag instead of a lot of conditional code.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
The same name for different inputs is not a very good idea, can lead to problems on submit or even on getting the inputs, so basically you want to show certain element when you click certain button, right?
Say:
button1 > shows Input1
button2 > shows Input2
button3 > shows Input3

you could have something like:


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

I"m not a huge fan of obtrusive JavaScript (embedding script inside structural elements).

From the original description I"m still not quite sure what the issue is, but when some information specific to an element is needed by a handler, it's common to add custom attributes to elements to have something other than names to distinguish them. HTML5 style rules (which should also be used with HTML4) dictate that such attributes be named with the prefix data-.

For example:
When an event fires on one of the buttons, the values of the custom attribute for the event target can be used to distinguish what happens in the handler.

I don't know if any of this is relevant or not. But it may be.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using One Input for Multiple Functions
 
Similar Threads
Image insertion problem
Is there a possible way to use index properties on this situation
Change Program (How can I get two inputs)
XML file as String
use of pattern mathces