Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-03-2006, 02:00 PM   PM User | #1
kehers
Regular Coder

 
Join Date: Mar 2006
Location: Nigeria
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
kehers is an unknown quantity at this point
innerHTML and AJAX

Im trying to use Ajax to validate a form field as soon as the user blurs from the field.
Here is what the code looks like:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Demo 2 - Getting a page's content</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<SCRIPT type="text/javascript">
function alrt(){
alert("sup baby!")
}
function HttpRequest(url){
var pageRequest = false //variable to hold ajax object
/*@cc_on
   @if (@_jscript_version >= 5)
      try {
      pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
      }
      catch (e){
         try {
         pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
         }
         catch (e2){
         pageRequest = false
         }
      }
   @end
@*/

if (!pageRequest && typeof XMLHttpRequest != 'undefined')
   pageRequest = new XMLHttpRequest()

if (pageRequest){ //if pageRequest is not false
   pageRequest.open('GET', url, false) //get page synchronously 
   pageRequest.send(null)
   embedpage(pageRequest)
   }
}

function embedpage(request){
//if viewing page offline or the document was successfully retrieved online (status code=2000)
if (window.location.href.indexOf("http")==-1 || request.status==200)
   document.getElementById("contentdiv").innerHTML = request.responseText
//document.write(request.responseText)
}

</SCRIPT>

</HEAD>
<BODY>
<DIV id=contentdiv></DIV><INPUT onclick="HttpRequest('ds.php?staff_id=7');" type=button value="Get content"> 
</BODY></HTML>
Where ds.php goes this way:
PHP Code:
<?php
include("db.inc");

$staff_id $_REQUEST['staff_id'];

$query "select staff_id from personnel_master where staff_id='$staff_id'";
$result mysql_query($query);

if(!
$result)
echo 
mysql_error();

if(
mysql_num_rows($result) < 1)
echo 
"<div style='border: 1px solid red'>Staff with staff id: <b>$staff_id</b> not found!</div>";
?>
This works fine but when i tried echoing back a script
this way,
PHP Code:
if(mysql_num_rows($result) < 1)
echo 
"
<script>
alert('Staff not found!');
</script>
"

it doesnt work. does anyone know how to get round this?
kehers is offline   Reply With Quote
Old 06-04-2006, 12:18 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Try putting the echo statement on one line and use \n to represent the new line characters in the output.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-04-2006, 04:43 PM   PM User | #3
kehers
Regular Coder

 
Join Date: Mar 2006
Location: Nigeria
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
kehers is an unknown quantity at this point
doesnt work. :-(
kehers is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:13 PM.


Advertisement
Log in to turn off these ads.