med267 Posted June 24, 2009 Share Posted June 24, 2009 Hi * Any help with this would be a godsend. The script scrambles my email address(prevent spam harvester), but prints it the correct readable way when the page is viewed. My problem is I get undefined showing up in my page just before declaring OT=""; It is driving me crazy as I dont know much javascript. I just tried to repurpose another script found elsewhere. Any help or pointers getting rid of that undefined showing up, but still outputting my readable email in the document.write would be really appreciated <li><span id='mEncEmail1'>(JavaScript must be enabled to view this email address)</span><script type="text/javascript"> //<![CDATA[ ML="dgotns/c@=f:eulwaimjp. \"h>r<"; MI="K@FHJ<:9GB@A>32;C<::E1=53@:552481B@A>E72BGI?<00A41587=DA05?<00A41E72BK6@I"; OT=""; for(j=0;j<MI.length;j++){ OT+=ML.charAt(MI.charCodeAt(j)-48); } document.getElementById('mEncEmail1').innerHTML = document.write(OT); //]]> </script></li> Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted June 24, 2009 Share Posted June 24, 2009 It looks like your first line is the culprit. You exit the string, then leave a dangling h>r<. You then restart the string with the next double-quote. Quote Link to comment Share on other sites More sharing options...
med267 Posted June 24, 2009 Author Share Posted June 24, 2009 Thank you for your reply. I understand a little about what what you are saying escaping the quote and leaving the dangling h>r< but doesnt the quote after r<" close it even though the previous " is escaped? Still not sure how to get it assigned to the correct value & output it to the document.write without the undefined showing up on the page before the document.write happens. I have tried escaping & trying extra double quotes, but my inexperience definitely shows itself at every attempt. If you or anyone has anymore insight into this it would be really helpful. ML="dgotns/c@=[f:eulwaimjp. \"h>r<"; MI="K@FHJ<:9GB@A>32;C<::E1=53@:552481B@A>E72BGI?<00A41587=DA05?<00A41E72BK6@I"; Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 25, 2009 Share Posted June 25, 2009 Change document.getElementById('mEncEmail1').innerHTML = document.write(OT); to document.getElementById('mEncEmail1').innerHTML = OT; Quote Link to comment Share on other sites More sharing options...
med267 Posted June 25, 2009 Author Share Posted June 25, 2009 Removing the document.write worked. Thank you very much. Now i am trying to wrap my head around why it worked as compared to the document.write. Any explanation would be great. I guess I need to find a way to echo the output on a per line basis. Thanks again for showing me, until I understand it better. Have a great day. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 25, 2009 Share Posted June 25, 2009 document.write() method does not return a value. It outputs text to the page. That's it. For example - function write (arg) { document.body.innerHTML = arg; } var e = write('foo'); e doesn't contain a value because the function doesn't return a value. It's like how document.write() doesn't return any values. It just does something to the screen. If you want to write some undefined value, it complains. You're just storing text into an element, so you don't need document.write(). In fact, it didn't make sense. What you had before is saying you want to store the value of the output of OT (from document.write) to inside the element mEncEmail. Of course that makes no sense. You want it to say - store the value of OT inside the element mEncEmail. Quote Link to comment 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.