...

View Full Version : how do i check if document.getElementById('email2') exists before getting its value



needsomehelp
09-15-2011, 09:50 AM
is there a way to do this with javascript ?



var fID = document.getElementById('email2');

coothead
09-15-2011, 10:55 AM
Hi there needsomehelp,

does this help...


<script type="text/javascript">

function init(){

var fID=document.getElementById('email2');

if(fID){
/* replace this alert with appropriate code */
alert('fID exists');
}
else {
alert('fID does not exist');
return;
}
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);

</script>

coothead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum