AJAX: making text appear on right, after entered.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

AJAX: making text appear on right, after entered.

Post by simonmlewis »

Code: Select all

<script type="text/javascript">
function checkurl(str)
{
if (str=="")
  {
  document.getElementById("txtUrlHint").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("txtUrlHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","urlcheck.php?q="+str,true);
xmlhttp.send();
}
</script>
<input type='text' name='url' onchange=\"checkurl(this.value)\"><br/>

Code: Select all

<?php
$q=$_GET["q"];
if ($q != NULL) { echo $q;}
?>
The top is a snippet from the page. If I enter a full URL, the txtUrlHint will display the URL on my page on the right.
But if I just enter a YouTube embedded code, ie this:
[text]<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/U6mm8W4ej2c?fs ... ram><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/U6mm8W4ej2c?fs=1&hl=en_GB" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>[/text]
It doesn't work. I was expecting it to display the video on the right.

Does anyone know why it won't do it?

IN ADDITION TO THIS....How do you work with Ajax on a Hyperlink?
So if I wanted to have the <object> appear on the right of the page by posting it thru Ajax to a video.php page, and it just appears?
Onchange works via a form field. How do you do it through A HREF??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply