• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Script Onclick event with pre selected radio buttons

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can java script onClick event work with pre-selected radio buttons?
I read that onClick works only when mouse is clicked. Here , I am gonna get pre-selected radio buttons and accordingly it will execute onClick event for that pre-selected radio button when page gets loaded.

Thanks.





 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

namita sasa wrote:I read that onClick works only when mouse is clicked.


That's kind of the definition of "onClick", no?

namita sasa wrote:I am gonna get pre-selected radio buttons and accordingly it will execute onClick event for that pre-selected radio button when page gets loaded.


That's something different: you should use a JavaScript library to find all the selected radio buttons (probably of a specific name or class) and call a JavaScript method when the DOM is ready. That's a one-liner in most JavaScript libraries.

I'm moving this post to HTML/JavaScript as it has nothing to do with Struts.
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone throw more light on this?
 
Sheriff
Posts: 67753
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
Yes. As David said, a click event happens as the result of a click. It has nothing whatsoever to do with radio button state.

If you want to do something with regards to radio button state, you'll need to inspect that state at whatever point it's of interest to you. If that's at page load time, then you'd do it in the onload handler (or jQuery ready handler, if using jQuery).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic