Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

element.attachEvent issues

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
Hi All,

Stuck trying to add event handles to a form which is dynamically generated. At the end of the main page, I have a call like this


Code:
<script language='javascript'>SetStatus(0);registerMyEvents();</script>

and then in my function I want to do this

Code:
function registerMyEvents()
{
  if (document.getElementById('EMAIL'))          { document.getElementById('EMAIL').attachEvent('onblur',checkStatesForIdCapture);            }
  if (document.getElementById('STATE_ID_NUMBER')){ document.getElementById('STATE_ID_NUMBER').attachEvent('onblur',checkStatesForIdCapture);  }
  if (document.getElementById('STATE_ID_STATE')) { document.getElementById('STATE_ID_STATE').attachEvent('onchange', checkStatesForIdCapture; }
}

When I do that I get an error in another part of the main page, but when the function is cleared out, the page loads fine.

I am sure that I have done something dumb, and if someone could point me in the correct direction, I'd appreciate it





Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Are you running this code in IE? if not, that might be it, as attachEvent is IE-only AFAIK...

See for more on making a cross-browser solution.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
It is IE only, and that is ok as the client only runs IE. Once I get it working on IE, i will be changing this to be more cross browser compliant

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Hi

Just correct the syntax and should work :
Code:
function registerMyEvents()
{
  if (document.getElementById('EMAIL'))          { document.getElementById('EMAIL').attachEvent('onblur',checkStatesForIdCapture);            }
  if (document.getElementById('STATE_ID_NUMBER')){ document.getElementById('STATE_ID_NUMBER').attachEvent('onblur',checkStatesForIdCapture);  }
  if (document.getElementById('STATE_ID_STATE')) { document.getElementById('STATE_ID_STATE').attachEvent('onchange', checkStatesForIdCapture[COLOR=red pink][b])[/b][/color]; }
}


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top