ricmetal Posted March 18, 2009 Share Posted March 18, 2009 hey,why is this undefined? theDiv brings in 'this' function alertMe(theDiv){ var divId = theDiv.id; // when i alert divId i get the div's id var joe = document.getElementById(divId).innerText; //this is undefined, why? alert(joe); } Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/ Share on other sites More sharing options...
Festy Posted March 18, 2009 Share Posted March 18, 2009 have you tried 'innerHTML' instead of 'innerText' ?? Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787540 Share on other sites More sharing options...
ricmetal Posted March 18, 2009 Author Share Posted March 18, 2009 yes still undefined, i also tried .value Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787542 Share on other sites More sharing options...
Festy Posted March 18, 2009 Share Posted March 18, 2009 can you post your error message and/or html code please ? Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787546 Share on other sites More sharing options...
ricmetal Posted March 18, 2009 Author Share Posted March 18, 2009 the error message is a just popup saying "undefined" <div id='usr".$OID."' contentEditable='true' onblur='alertMe(this)'>".$userVar."</div> function alertMe(theDiv){ var divId = theDiv.id; // when i alert divId i get the div's id var joe = document.getElementById(divId).innerText; //this is undefined, why? alert(joe); } Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787549 Share on other sites More sharing options...
ricmetal Posted March 18, 2009 Author Share Posted March 18, 2009 i cant post all the code, is alot of it but the div is inside a td, inside another div so div>table>tr>td>div(the one im trying to get the id of) i should strat looking for known getElementById bugs.. :/ ! $OID is a number Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787555 Share on other sites More sharing options...
ricmetal Posted March 18, 2009 Author Share Posted March 18, 2009 <html> <body> <div id='usr19'>heyas manass panas !</div> <script type="text/javascript"> var joe = document.getElementById('usr19').innerText; alert(joe); </script> </body> </html> this doesnt even work, let alone my code Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787573 Share on other sites More sharing options...
ricmetal Posted March 18, 2009 Author Share Posted March 18, 2009 have you tried 'innerHTML' instead of 'innerText' ?? note: innerHTML works i was using innerHtml Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.