views:

30

answers:

1

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/looks for a div called #box and is containing "1", then it should: window.parent.showMessage("Video Is OK");

I use jquery too

+3  A: 
if ($("#box[value=1]").length > 0) { alert("Video is OK"); }
David Morton
Where should i put this in my script?
Karem
Anywhere really. Just put it on the page, in a script tag, that it references. It'll run every time the page has completed loading.
David Morton
But i want it to check after if(http.readyState == 4){ ??
Karem
Can i do that there?
Karem
I apologize. I've changed the original code. Put it after document.getElementById('insert_response').innerHTML = '' + response;... but still within the function.
David Morton
And i cant really find anywhere in the code you wrote, where it search insert.php for #box/ response text?
Karem
That's what the selector does. "#box:contains('1')" is a selector that searches the DOM for a div with an id of "box" whose inner html contains "1".
David Morton
Okay. Ive did it like this:document.getElementById('insert_response').innerHTML = response;if ($("#box:contains('1')").length > 0) { alert("Video is OK"); }and in the insert.php i have this:<input type="hidden" id="box" value="1"> but it still doesnt give me an alert
Karem
Earlier, you said "box" was a div, not an input.... when did it change to an input? Try changing the selector to: "#box[value=1]". Updated the code again...
David Morton
Thank you so much David, for helping out! And replying to my comments so fast. Im sorry ive said div instead of input, a little typo fail from my side.. sorry. This works perfect now. Thanks again, you were really helpful
Karem
Glad I could help :)
David Morton