Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

alert(innerHTML);

Hi Experts, I have a table name "myTable" with two columns cell(0) and cell(1). In a cell(0), I put button name "Try it" and on a cell(1), I put input type=text with a name "qty." I want to obtain the value of "qty" and display it on alert. HOW? I attached the codes to make experts easy to understand my goal. Thank you!
AlertButtonOnTable.Html
SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are a number of ways of doing this.

Simple jQuery solution
<script src="http://code.jquery.com/jquery.js"></script>
<script>$(function() {
  $('button').click(function() {
    alert($(this).closest('tr').find('input').val());
  });
});
</script>

Open in new window

Avatar of Whing Dela Cruz

ASKER

Hi Bryan Tao,
Julian codes is working while yours is not. But I'm still interested with your solution. When I implement your code no alert will come out! Thanks!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Julian, Thank you for providing Java solutions as i am prefer  to Java rather than jQuery. Thank you also Bryan Tao for leading me closer to the solutions. More power to both of you, and God bless!
You are welcome
Thank you for providing Java solutions as i am prefer  to Java rather than jQuery
1. NB Java does not equal JavaScript - important to make the distinction
2. jQuery is JavaScript - it is just a library that makes doing things with the DOM a whole lot easier. In this case it was a simple requirement but when you start getting into complex DOM interactions you are going to find jQuery gets you where you want to go a whole lot quicker.
Thank you Julian, at first, I felt uncomfortable of using it (jQuery) because of the codes that is not understandable  to me as I opened and saw codes inside jQuery. Now i realize  the advantage of using it compared to the so called Java alone . Thank you once again for this great advice more power and God bless!
I don't know why mine didn't work.  Here's the HTML file.  It works for me on both Chrome and IE.
test.html