Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  99] [ 2]  / answers: 1 / hits: 16190  / 12 Years ago, sat, november 17, 2012, 12:00:00

In my jsp page, I have one button and one label. When page loading, the text of the label box is Test. Suppose, user clicks the button then I have to change the text of the label into tested.



I am new to Jsp.So, Please guide me to get out of this issue...


More From » java

 Answers
6

You would first need to set a listener to your button, say our markup was as follows:



<button id='btn'>test it</button>
<span id='label'>Test</span>


We can select the button element, and set it's onclick attribute:



document.getElementById('btn').onclick = test


Then we can define a function call test that will toggle the label:



function test(){
document.getElementById('label').innerHTML = 'Tested';
}


And that's it!



Here's a jsfiddle demonstrating this code.


[#81946] Thursday, November 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
3 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;