squiblo Posted June 18, 2010 Share Posted June 18, 2010 I have made a good working chat and these are the steps the chat goes through to output new messages. 1. Count number of words in the chat .txt file 2. Count number of words in the div where the chat is outputted 3. If the word counts are both the same check again 4. If they are different then the div innerHTML will = the chat .txt file the problem is that i want it to me milliseconds faster, and counting words does not seems the most logical way to check if they are different. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
F1Fan Posted June 18, 2010 Share Posted June 18, 2010 Why don't you check if the string in the chat box is equal to the string in the text file? Quote Link to comment Share on other sites More sharing options...
squiblo Posted June 18, 2010 Author Share Posted June 18, 2010 becuase using innerHTML slightly changes code for example in IE <span id='test' style='color:red'> will change to <SPAN id=test STYLE="color:red"> but in firefox innerHTML changes the code differently, so they could be the same in some browsers but maybe not in others, if you get me Quote Link to comment Share on other sites More sharing options...
F1Fan Posted June 18, 2010 Share Posted June 18, 2010 That doesn't seem right. Browsers don't inject HTML, they just display what you coded. Plus, if that was the case, the string length of <span id='test' style='color:red'> and <SPAN id=test STYLE="color:red"> are not the same, due to the missing single quotes around "test." Quote Link to comment Share on other sites More sharing options...
squiblo Posted June 18, 2010 Author Share Posted June 18, 2010 I have just done a check.. this is a sample of what is in my .txt file (just entering random gibberish) <LI>VFOMB<INPUT type="hidden" value="administrator1"></LI> <LI>ORROR<INPUT type="hidden" value="administrator1"></LI> <LI>GVVMF<INPUT type="hidden" value="administrator1"></LI> <LI>FOEFMVE<INPUT type="hidden" value="administrator1"></LI> <LI>EVORG<INPUT type="hidden" value="administrator1"></LI> <LI>RGOVK,R<INPUT type="hidden" value="administrator1"></LI> but when i alert what is in the content of the div where the chat is outputted it shows this... <li>VFOMB<input type="hidden" value="administrator1"></li> <li>ORROR<input type="hidden" value="administrator1"></li> <li>GVVMF<input type="hidden" value="administrator1"></li> <li>FOEFMVE<input type="hidden" value="administrator1"></li> <li>EVORG<input type="hidden" value="administrator1"></li> <li>RGOVK,R<input type="hidden" value="administrator1"></li> here I used google chrome, and in IE it changes tags into capitals Quote Link to comment Share on other sites More sharing options...
F1Fan Posted June 18, 2010 Share Posted June 18, 2010 If it's just a case thing, just convert both to all lowercase before comparing them. Quote Link to comment Share on other sites More sharing options...
squiblo Posted June 18, 2010 Author Share Posted June 18, 2010 also single quotes and double quotes are added or removed depending on the browser, how could I get past that? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted June 18, 2010 Share Posted June 18, 2010 You could do a replace on both, just replace all double quotes with singles, again just for the compare. Really, you should just put this into a database. Then you could store the ID of the most recent chat in a hidden input, then add any new lines and update the latest ID. That would be faster yet, because you could then just add the new data to the field, rather than replacing the whole thing. 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.