• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using One Input for Multiple Functions

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic