views:

56

answers:

1

Hello. I am using this script to insert comment to the database:

var http = createObject();
var nocache = 0;
function insert() {
document.getElementById('insert_response').innerHTML = "To Sek .. "
var fID= encodeURI(document.getElementById('fID').value);
var kommentar= encodeURI(document.getElementById('kommentar').value);
nocache = Math.random();
http.open('get', 'insert.php?fID='+fID+'&kommentar=' +kommentar+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
 function insertReply() {
 if(http.readyState == 4){
 var response = http.responseText;
 document.getElementById('insert_response').innerHTML = ''+response;
 }
} 

Right now it innerHTML out the response text, that comes from insert.php.

But inside insert.php, i have setted up some "restrictions" in PHP like if empty, if double post etc. etc. I can therefore not place in: window.parent.showMessage("Video Is OK"); after if(http.readystate == 4)..

So i would like to do another function to this script, that checks If the div box #box is containing "1", then: window.parent.showMessage("Video Is OK");

how can i do that? thanks

A: 

Are you passing any errors back to the user (e.g. on double posts, empty posts, too long posts)? If you are, and you don't pass anything back on success you could check the length of the response and show your "Video IS OK" message if the length is zero:

if(http.readyState == 4) {
  var response = http.responseText;
  if (response.length > 0)  {
    // success
    window.parent.showMessage("Video Is OK");
  } else {
    // something went wrong, show error message
    document.getElementById('insert_response').innerHTML = response;
  }
}
Chris Pebble
I am passing errors, but i am also passing on success. So will not work
Karem
You can check for specific text using .indexOf() to determine pass/fail. Alternatively you could pass back json data containing a boolean to determine if the action was successful.
Chris Pebble
Cant you do it the way i said, checking a <div> box if it contains 1 then display window.parent.....?
Karem
How is `1` being populated inside the `<div>`? It doesn't appear to be in the code you posted. If you could clarify that I'd love to help.
Chris Pebble