maqskywalker
asked on
apply javascript eventlistener on multiple textboxes whose id starts with
I'm working with JavaScript eventlistener
Right now I have this:
// ----- Event Listener - TextBox Click -----
document.getElementById('D ataGridA_t xtBox1').a ddEventLis tener('cli ck', function () {
// get value of textbox and save in variable
var x = document.getElementById("D ataGridA_t xtBox1").v alue;
// after clicking in textbox save existing textbox value in hiddenfield1
document.getElementById('H iddenField 1').value = x;
})
// ----- Event Listener - TextBox Click -----
The above event listener works fine.
When I click in a Textbox called DataGridA_txtBox1, then the value of the textbox is stored in HiddenField1
What if I have 3 textbox on my page.
The texboxes on my page would be called this:
DataGridA_txtBox1
DataGridA_txtBox2
DataGridA_txtBox3
I only want to have one event listener.
Is there a way so revise my click event so that the click event applies to any textbox whose id starts with DataGridA_txtBox?
Right now I have this:
// ----- Event Listener - TextBox Click -----
document.getElementById('D
// get value of textbox and save in variable
var x = document.getElementById("D
// after clicking in textbox save existing textbox value in hiddenfield1
document.getElementById('H
})
// ----- Event Listener - TextBox Click -----
The above event listener works fine.
When I click in a Textbox called DataGridA_txtBox1, then the value of the textbox is stored in HiddenField1
What if I have 3 textbox on my page.
The texboxes on my page would be called this:
DataGridA_txtBox1
DataGridA_txtBox2
DataGridA_txtBox3
I only want to have one event listener.
Is there a way so revise my click event so that the click event applies to any textbox whose id starts with DataGridA_txtBox?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help.
ASKER