I have a simple form that contains one text field:
<input name="fName" type="text" id="fName"
maxlength="25" value="<?php echo $_SESSION['SES_fName']; ?>"
onblur="myObj.setValues('f1', this.value, name)"/>
When I click into the cell of this text box is an event fired?
If it is what kind of information can I retrieve from this event?
Can I obtain the textboxes id, the name of the field, any of the attributes?
I am trying to find a way to automate how I capture information for forms validation
Right now I have everything hard coded and it takes alot of work and maintenance.
PS I am pretty sure that jquery, YUI, and the likes would make life pretty easy,
but the learning curve here is just as important as getting the job done.
In other words I need to find the limitations of what can and can't be done.
any insight would be greatly appreciated
Kevin
events - what can and can't be done when they fire
Moderator: General Moderators
Re: events - what can and can't be done when they fire
In event listener function 'this' keyword will reference an input, so you can get any attribute (id, name, value, etc.) of the input.When I click into the cell of this text box is an event fired?
Example (won't work in IE):
Code: Select all
var node = document.getElementById('fName');
node.addEventListener('blur', function () {
alert(this.name);
alert(this.value);
alert(this.id);
}, false);Re: events - what can and can't be done when they fire
This is exactly what I was looking for
Now is there a reason that I should not take all of the work out of the form?
Right now I use blur to call a function to set my data fields. onblur=setMyDataFields(this.name,this.value,this.id);
I would like to automate everything so that all I have to do is include my js script
So what kind of trouble would I get myself into if I automated everything?
Is there a graceful way of checking to see if what I want to do is available so that I can use a try catch block if everything falls apart?
thanx
Kevin
Now is there a reason that I should not take all of the work out of the form?
Right now I use blur to call a function to set my data fields. onblur=setMyDataFields(this.name,this.value,this.id);
I would like to automate everything so that all I have to do is include my js script
So what kind of trouble would I get myself into if I automated everything?
Is there a graceful way of checking to see if what I want to do is available so that I can use a try catch block if everything falls apart?
thanx
Kevin
Re: events - what can and can't be done when they fire
Well I thought I had found my silver bullet:
but IE won't play nice
Is there anyway to capture the onblur event when a user leaves a textinput field
in an IE browser? I can capture the CLICK event, but that is only one that I have
been able to capture thus far.
I've tried everything that I could find out there and I have hit a brick wall
Spent hours going over the MSDN's site and couldn't find anything there either
The closest thing that I could find is window.event, but it fails in IE 8
I don't have earlier versions of IE to test on YET
Can anyone help me solve this mistery?
thanx
Kevin
,var node = document.getElementById('fName');
node.addEventListener('blur', function () {
alert(this.name);
alert(this.value);
alert(this.id);
}, false);
but IE won't play nice
Is there anyway to capture the onblur event when a user leaves a textinput field
in an IE browser? I can capture the CLICK event, but that is only one that I have
been able to capture thus far.
I've tried everything that I could find out there and I have hit a brick wall
Spent hours going over the MSDN's site and couldn't find anything there either
The closest thing that I could find is window.event, but it fails in IE 8
I don't have earlier versions of IE to test on YET
Can anyone help me solve this mistery?
thanx
Kevin
Re: events - what can and can't be done when they fire
Maybe:
[js]var node = document.getElementById('fName');node.onblur = function () { alert(this.name); alert(this.value); alert(this.id);}[/js]
[js]var node = document.getElementById('fName');node.onblur = function () { alert(this.name); alert(this.value); alert(this.id);}[/js]
There are 10 types of people in this world, those who understand binary and those who don't
Re: events - what can and can't be done when they fire
As I wrote it won't work in IE, because it doesn't support standard even registration.
For cross-browser solution see http://www.quirksmode.org/js/events_advanced.html
For cross-browser solution see http://www.quirksmode.org/js/events_advanced.html