/    Sign up×
Community /Pin to ProfileBookmark

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:
[url]http://w3schools.com…ax_database.asp[/url]

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>[/CODE]

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();
}[/CODE]

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>”;
}
[/CODE]

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>”;
}

[/CODE]

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>
[/CODE]

but i get these strange result:

[CODE]
<div>
<p>it’s true</p>
</div>[/CODE]

I hope u got my means.
I don’t want print [COLOR=”Red”]</div> tag[/COLOR] ….I just wana see[COLOR=”red”] <div> tag[/COLOR] in my html source code.
what can I do to solve this problem?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@g0dzuki99May 24.2012 — 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.
×

Success!

Help @abahaedini spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...