www.webdeveloper.com
Results 1 to 2 of 2

Thread: strange result in "echo" (php/ajax)

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    1

    strange result in "echo" (php/ajax)

    Hi

    I wana check value of an input text for validation by ajax.

    I read a great tutorial in w3schools.com in here:
    http://w3schools.com...ax_database.asp

    and I changed it for my business.

    so I have 3 file:
    in index.php
    Code:
    <div class="fieldwrapper">
      <div class="thefield 1" id="idn1">
            <input name="password" type="password" value="" size="30" onchange="showUser(this.value)"/>
      </div>
    </div>


    and and some of code in second file: load.js


    Code:
    function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("idn1").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("idn1").innerHTML=xmlhttp.responseText;
            }
      }
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
    }


    and finaly, in third file: (external php): idn1.php

    Code:
    <?php
    $q=$_GET["q"];
     
      if(strlen($q) <6 && strlen($q) <> NULL)
            {
     echo "<p> it's true </p>";
              }  
     
     
      else
            {
      
      echo "<p> it's true </p>";
            }


    this php/ajax code works great...


    Now I wana write a single "html tag" in my code in idn1.php (not double html tag)
    like this:
    Code:
    <?php
    $q=$_GET["q"];
     
      if(strlen($q) <6 && strlen($q) <> NULL)
            {
       echo "<p> it's true </p>";
     
     
              }  
     
     
      else
            {
       echo "<div>";
       echo "<p> it's true </p>";
            }

    for (strlen($q) >=6), when I look in index.php html source code (by browser [google chorme- [inspect element])
    I expect view these result:

    Code:
    <div>
    <p>it's true</p>
    but i get these strange result:


    Code:
    <div>
    <p>it's true</p>
    </div>

    I hope u got my means.
    I don't want print </div> tag ....I just wana see <div> tag in my html source code.
    what can I do to solve this problem?

  2. #2
    Join Date
    May 2012
    Posts
    37
    Chrome is trying to fix your markup error so the page renders correctly. You can't have an open <div> without out it's closing counterpart, when Chrome renders the page it's saying, 'uh oh... this guy forgot to close his div tag' and adding it for you.

    Chrome definitely does this and I would suspect any other modern browser will too.

    Solution... use proper markup.
    Last edited by g0dzuki99; 05-24-2012 at 02:15 PM. Reason: I can't spell and type at the same time.
    "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
    -- Douglas Adams

    http://www.chaoscontrol.org
    Have you minified your CSS/JS lately?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles