Fire Events or Functions When Text Box Gets Focus
Posted: Wed Apr 28, 2010 1:26 pm
On my PHP Page I have this JavaScript to add a New Row to a Table and inser Text Box in the cells:
(only part of the function is given here as it is the most relevent code snippet for our discussion of the stated problem)
When the function containing the above piece of codes is called (onClick event of a button), it addes a row and inserts a Text Box in the 3rd cell.
Here, I want to be able to pop-up a Calander when we click on the text box or the text box gets focus set on it (as by Tab).
I tested whether I could use any function by using these two events:
The Aler Box does pop-up but only when we click the "Add" button on the form to add a New Row. When click in the Text Box or press the Tab key to set focus on it, nothing happens.
If we can fire the alert() function as we want here, then we can call a function to show a calander too.
Any suggestions?
(only part of the function is given here as it is the most relevent code snippet for our discussion of the stated problem)
Code: Select all
var newCell2 = newRow.insertCell(2);
var el = document.createElement('input');
el.type = 'text';
el.name = 'rec[]';
el.id = 'txtRow' + iteration;
el.size = 20;
newCell2.appendChild(el);
When the function containing the above piece of codes is called (onClick event of a button), it addes a row and inserts a Text Box in the 3rd cell.
Here, I want to be able to pop-up a Calander when we click on the text box or the text box gets focus set on it (as by Tab).
I tested whether I could use any function by using these two events:
Code: Select all
el.onClick = alert("Hello!");
el.onChange = alert("Hello!");
If we can fire the alert() function as we want here, then we can call a function to show a calander too.
Any suggestions?