• 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

I want to pass 2 element ids to a single event handler function onclick. is it possible?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 input elements of type text and hidden


the hidden element's id also should be dynamic as there are many hidden elements in my code.

So, on click of text type element, hidden element's value also should be set. Is it possible? if yes, can anyone please reply with appropriate code?
 
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
With enough code in the onclick attribute you could probably do it -- but that's going to be really clunky and fragile. Why are you needing to of this? We can likely come up with a better way.

Are you not using jQuery? If not, why not?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:With enough code in the o'clock attribute you could probably do it



Auto-correct playing up?
:)
 
Bear Bibeault
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
Yup. Sigh -- fixed. Thanks.
 
Gowthami Bethanabotla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Bear Bibeault

Yeah, JQuery also can be used. but Im not much comfortable with it.
If you suggest that Jquery would be better for this type of requirement, I will go for that.
Can you please specify how I can call a Jquery function with 2 element id's dynamically and change their values in JQuery function  ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jQuery would make this much easier.

You wouldn't need id attributes at all. The clicked element is available in the event handler as this, and then you can find the sibling element without needing an id.

The jQuery methods to focus upon are click() to establish the click handler, closest() to find parent elements, and find() to find child elements.

Give it a try and see how close you can get.
 
Gowthami Bethanabotla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear Bibeault

Thanks for suggestion!!

I have used siblings() in the following way. Please have a look


On click of text type element, hidden element's value also should be set. So, I am trying to use the below jQuery script


with "$(this).siblings('input:hidden').val(i); " line , variable "s" value is undefined. nothing is happening
I am not able to get the existing hidden element value to a variable by "var x= $(this).siblings('input:hidden').val();"

I have tried using find() as well by

var s=$(this).find('input[type=hidden]').val(i);  - even though no luck..

Can you please suggest me where I did wrong ?

 
Bear Bibeault
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
Two observations:

  • Here's the docs for the :hidden pseudo-selector: https://api.jquery.com/hidden-selector/ Is it really what you need?


  • The .find() method searches the children of an element. Is it what you need?
  •  
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic