Jump to content

squiblo

Members
  • Posts

    483
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by squiblo

  1. I am working on a small chat feature and to be honest its working near enough perfect, there is just one more improvement I think I could make. The problem is that when the page loads the cursor style is "progress" because my chat keeps looping and looping never ending because it is always checking if "file.txt" has been updating by a user in the chat. Here is my code. function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } var xmlhttp1input; function chat1() { showUser1(); } function showUser1(str) { xmlhttp1input=GetXmlHttpObject1(); if (xmlhttp1input==null) { alert ("Browser does not support HTTP Request"); return; } var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); xmlhttp1input.onreadystatechange=stateChanged1; xmlhttp1input.open("GET",url1,true); xmlhttp1input.send(null); } function stateChanged1() { if (xmlhttp1input.readyState==4) { var response = trim(xmlhttp1input.responseText); var innerdiv = trim(document.getElementById("chatoneoutput").innerHTML); var count_response = trim(xmlhttp1input.responseText).split(" ").length; var count_innerdiv = trim(document.getElementById("chatoneoutput").innerHTML).split(" ").length; if (count_innerdiv != count_response){ document.getElementById("chatoneoutput").innerHTML = xmlhttp1input.responseText; var filelines_count = trim(xmlhttp1input.responseText).split("\n").length; var line = trim(xmlhttp1input.responseText).split("\n"); var username = document.getElementById('username_js').value; var user_id = document.getElementById('user_id_js').value; var lastline_check = username + user_id; var last_line = line[filelines_count - 1]; var matchPos1 = last_line.search(lastline_check); var sound_enabled = document.getElementById('sound_enabled_js').innerHTML; if (sound_enabled == 1) { if (matchPos1 == -1) { (function alert_sound() { var audio = $('<audio />', { autoplay : 'autoplay' }); addsource(audio, 'http://localhost/sounds/chat_sound.ogg'); addsource(audio, 'http://localhost/sounds/chat_sound.mp3'); audio.appendTo('body'); function addsource(elem, path) { $('<source />').attr('src', path).appendTo(elem); }; })(); } } } showUser1(); } } My main question I would like answered - is there a better way to do the same thing I have done above? If you have any questions about the above code then I will do my best to explain. I am using .txt files to save the chats basically just because I want to, but if you can persuade me to use SQL then I might just think about it. Thanks
  2. That's upsetting haha, but I suppose it's for the best, thanks haku.
  3. In the head tags of my page is have this.. <script type="text/javascript" src="http://localhost/includes/javascript.js"></script> and at the moment I am putting all the my JavaScript in that file, but that file is now becoming seriously long, and harder to read, is there a way to split the file up into many different files, to make it easier to understand and read. I have tried putting two script tags like this, but this did not seem to work. <script type="text/javascript" src="http://localhost/includes/javascript.js"></script> <script type="text/javascript" src="http://localhost/includes/javascript2.js"></script> What can I do to make it easier for myself? Thanks.
  4. No that has not worked I'm afraid Stealth
  5. I have a few div tags, the 3 I am concentrating on are "full_shadow", "padding_shadow" and "leave_chat" as shown below... <div id='full_shadow' style='display:none'> <div id='padding_shadow'> <div id='leave_chat'> <h3>Are you sure you want to leave this chat?</h3> <div style="float:left;padding-left:40px;padding-top:30px"> <img src='http://localhost/images/leave_chat.png'> <h3>Yes</h3> </div> <div style="float:right;padding-right:40px;padding-top:30px"> <img src='http://localhost/images/cancel_leave_chat.png' onClick="cancel_leave_chat();"> <h3 onClick="cancel_leave_chat();">No</h3> </div> </div> </div> </div> and here is the css... #full_shadow { position: absolute; top: 0; left: 0; width: 100%; height: 927px; background-color: #848484; /* for IE */ filter:alpha(opacity=60); /* CSS3 standard */ opacity:0.6; z-index: 1; } #padding_shadow { height: 200px; width: 300px; position: absolute; top: 50px; left: 50px; background-color: #3D3D3D; z-index: 2; } #leave_chat { height: 200px; width: 300px; margin-left: -10px; margin-top: -10px; background-color: white; border: 1px solid black; z-index: 3; } My problem is that I only want the "full_shadow" div to be opaque but I can see content underneath the "leave_chat" div. I have attached a screenshot of my problem, so you can get a better understanding. Thanks. [attachment deleted by admin]
  6. Currently I have something like this.. onmouseover="showTooltip(event,'TEXT GOES HERE');return false" I would like to put an "img" tag where the text goes, like this... onmouseover="showTooltip(event,'<img src='image'');return false" But that is obviously not going to work, I have also tried the following, but these also do not work, please help onmouseover="showTooltip(event,\"<img src='image'\");return false" onmouseover="showTooltip(event,"<img src='image'");return false"
  7. This is what my directories look like... I want to put a .htaccess file in the nav folder. Currently if I view a file in the nav folder the url will look like, "http://localhost/nav/about.php" but I want the same content to be shown if the url was "http://localhost/about.php" (without the 'nav/'). Thanks
  8. http://www.youtube.com/user/phpacademy#p/u/5/Ph2s7bCN23Q
  9. I'm not looking for a job as a web developer yet, I am 17 years old and believe I am good at what I can do for my age as I have not had much experience I am interested in web development and want to get a familiar understanding as to how to apply for jobs in maybe about 10 years from now, but at the moment I am dedicated to learning and becoming better at what I love doing.
  10. In a portfolio what certain things will an employer be looking for? If the jobs was for a PHP & MySql programmer?
  11. Is this the main way of doing it? The only way? Or are there other options?
  12. I am searching through websites just looking at how companies employ web developers, using recruitment agencies. And in one of the adverts I noticed the following sentence. - How is a portfolio constructed to show the agency or the company recruiting? - How can you put together a portfolio that can be proven to be your own genuine work?
  13. the following does not work because I cant get my slashed correct please help var replace_endli = "</LI>"; // </LI> var innerdiv = innerdiv.replace(/<\/li>/g, replace_endli);// </LI>
  14. Solved! Thank you so much F1Fan
  15. I have found where the slight problem is, the code is saying they are different even when they are the same, so im trying to find why
  16. Please could somebody make these two functions into one function function showUser1(str) { xmlhttp1input=GetXmlHttpObject1(); if (xmlhttp1input==null) { alert ("Browser does not support HTTP Request"); return; } var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); xmlhttp1input.onreadystatechange=stateChanged1; xmlhttp1input.open("GET",url1,true); xmlhttp1input.send(null); } function stateChanged1() { if (xmlhttp1input.readyState==4) { if (document.getElementById("chatoneoutput").innerHTML != xmlhttp1input.responseText){ document.getElementById("chatoneoutput").innerHTML = xmlhttp1input.responseText; } } }
  17. Delaying the function call only reduces my problem a little, because when I highlight the text I can only highlight it for 500ms. I think I have a solution if you could please make these two functions into one function. With the 1 big function I will try this. - get response text - if response text = document.getElementById("chatoneoutput").innerHTML; - loop through again - if they are not equal go to a separate function that is not in the "loop" - and then put "document.getElementById("chatoneoutput").innerHTML = xmlhttp1input.responseText;" this way the whole stript is not being looped through, only a section of it is. function showUser1(str) { xmlhttp1input=GetXmlHttpObject1(); if (xmlhttp1input==null) { alert ("Browser does not support HTTP Request"); return; } var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); xmlhttp1input.onreadystatechange=stateChanged1; xmlhttp1input.open("GET",url1,true); xmlhttp1input.send(null); } function stateChanged1() { if (xmlhttp1input.readyState==4) { if (document.getElementById("chatoneoutput").innerHTML != xmlhttp1input.responseText){ document.getElementById("chatoneoutput").innerHTML = xmlhttp1input.responseText; } showUser1(); } }
  18. oh no sorry, I'm getting myself confused now, but the code I sent you seems to be doing the same thing you sent me back. extra And person 2 can only see what person 1 types because I am calling the first function at the end of the last function, which I dont want to do.
  19. Still if person 1 inputs text, person 2 cannot see the text unless person 2 manually refreshes the page
  20. var xmlhttp1input; function chat1() { showUser1(); } function showUser1(str) { xmlhttp1input=GetXmlHttpObject1(); if (xmlhttp1input==null) { alert ("Browser does not support HTTP Request"); return; } var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); xmlhttp1input.onreadystatechange=stateChanged1; xmlhttp1input.open("GET",url1,true); xmlhttp1input.send(null); } function stateChanged1() { if (xmlhttp1input.readyState==4) { document.getElementById("chatoneoutput").innerHTML=xmlhttp1input.responseText + " "; showUser1(); } } function GetXmlHttpObject1() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } This is the ajax that is getting the contents of a php file, in the php file there are queries and outputs of the chat. showUser1(); is what i put in to make it loop through infinite times.
  21. Or maybe I could check MySQL and alert something when a integer value increases by one in the table. How could this be done. Thanks
  22. I'm updating as quick as javascript or the browser can run buy calling the first function at the end of the last function that is why nothing can be highlighted etc :/
  23. I am inputting the text into a file like 'chat.txt' if this is any useful information?
  24. what I'm actually trying to do is make a chat, I have it working at the moment and the ajax script gets the chat text from a file I call the function again. But there are two problems with doing this: - cant click links in the chat - can highlight anything (because it is a calling the chat so quickly) so I only need to call the function when, the end user inputs text into the chat and when person x inputs text into the chat, instead of looping through it all the time. If you don't understand I'll try to explain again.
  25. How could this be done, (what could I google, what could I look into). There are two end users, person 1 clicks a button and an alert prompt pops up on his screen saying "you clicked the button" but also at the same time, person 2 recieves an alert prompt saying "person 1 click the button" and vice versa
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.