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); } Quote 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' ?? Quote 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 Quote 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 ? Quote 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); } Quote 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 Quote 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 Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/149953-why-is-this-undefined/#findComment-787627 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.