Jump to content

squiblo

Members
  • Posts

    483
  • Joined

  • Last visited

  • Days Won

    2

Posts posted by squiblo

  1. 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

  2. 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

  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. 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]

  5. 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"

     

  6. This is what my directories look like...

    htdocs/

        - index.php

        - file.php

        - file2.php

        nav/

              - about.php

              - help.php

              - contact.php

     

    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

     

     

  7. 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.

  8. 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.

     

    Applicants should be able to demonstrate a portfolio of sites developed with PHP/MySQL.

     

    - 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?

  9. 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;
    }
    
    
    }
    }
    

  10. 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();
    
    }
    }
    

  11. 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.

  12. 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.

×
×
  • 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.