wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Use Value of Another Tag in Onclick Event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Use Value of Another Tag in Onclick Event" Watch "Use Value of Another Tag in Onclick Event" New topic
Author

Use Value of Another Tag in Onclick Event

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1462
    
    1
I have an onclick event on an input tag. I want to use the value of another input tag as one of the parameters I am sending to the js function.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So get the value of the other input tag and send it to the JavaScript function.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1462
    
    1
David Newton wrote:So get the value of the other input tag and send it to the JavaScript function.


Thats what I want to do but I don't know how to reference the indirect(other) input tag's value as a parameter in the onclick attribute of direct(this) input tag.

I hope this makes sense, again I don't do a good job explaning somtimes.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Do you know how to get the value of another input element? What JS library are you using? It doesn't get a whole lot easier than this--you might want to brush up on some JavaScript/DOM fundamentals before proceeding much further, it'll make your life a lot easier.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1462
    
    1
David Newton wrote:Do you know how to get the value of another input element? What JS library are you using? It doesn't get a whole lot easier than this--you might want to brush up on some JavaScript/DOM fundamentals before proceeding much further, it'll make your life a lot easier.


I use jquery mostly. I know how to get the value of tag while I am in js. I was in the process in of a long explanation when I realized I was going the wrong direction with my whole approach. Sorry for the bother but I am sure I will have more questions to come. I am glad there is a place to go to when I run into problems.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

So, for the sake of those that follow: if you know how to get the value of an element when you're "in JS", what's the issue? The "onclick" handler attribute value *is* JavaScript, so you'd get the value of the input element and pass it to the onclick handler function. Again for the benefit of people that find this thread via a search for a similar question, it'd be nice if you posted the solution, even you end up going a different direction.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1462
    
    1
David Newton wrote:So, for the sake of those that follow: if you know how to get the value of an element when you're "in JS", what's the issue? The "onclick" handler attribute value *is* JavaScript, so you'd get the value of the input element and pass it to the onclick handler function. Again for the benefit of people that find this thread via a search for a similar question, it'd be nice if you posted the solution, even you end up going a different direction.


I on my page had a set of radio buttons and an input tag with an onclick attribute. When th input tag was clicked I was tring to send the value of the checked radio button as a prameter in the input tag onclick event. The onclick event displays a list based on the vale on the radio button set. My solution was to use the radio button onclick to get the list and use the select onclick to populate the input tag value.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I actually meant the value of the "onlick" attribute that uses the value of another input element.
 
GeeCON Prague 2014
 
subject: Use Value of Another Tag in Onclick Event