westman Posted May 19, 2012 Share Posted May 19, 2012 hi all,yer i know am a bad programer :facepalm:so what am trying to do is send 1 verible to php and keep the results in a ajax/java veriblehere is what i have so fear.. window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";$.post(url,{ oto_update: oto_update } , function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});chater.value = data;});//if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//}//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);} i have been testing it but i think thatchater.value = data;});is incorecteany help? Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2012 Share Posted May 19, 2012 (edited) What is chater a reference to? normally it would be a reference like (1) chater = document.getElementById("whatever_id_ref"); which chater.value = data; will reference to apply value returned OR jquery would use (2)$("#whatever_id_ref").val(data); (1)JS function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";var chater = document.getElementById("whatever_id_ref");$.post(url,{ oto_update: oto_update } , function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});chater.value = data;}); //if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//} //alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);} (2)Jquery function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php"; $.post(url,{ oto_update: oto_update } , function(data) {//alert('got response from server, updating page with ' + data);//output.innerHTML = data;});//chater.value = data; $("#whatever_id_ref").val(data);}); //if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//} //alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);} Edited May 19, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
westman Posted May 19, 2012 Author Share Posted May 19, 2012 chater is a varible that is empty when the script runs..var chater = "" and in the end i do no want "chater" leaveing the script.am looking to put all the data from oto_work.php in the varible of "chater", and to be used in javascript to run conditions (if, elts and so on..) Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2012 Share Posted May 19, 2012 (edited) In that case you would not use chater.value, as the '.value' is a reference to a value of a form input such as <input type="text" name="whatever" id="whatever" />, so you would just use chater = data;}); Edited May 19, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
westman Posted May 19, 2012 Author Share Posted May 19, 2012 still not seeing my alert boxmy php page looks like this...<?phpecho 'testing123';?>and javascript... window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";//var chater = "nnnnnn";$.post(url,{ oto_update: oto_update } , function(data) {//alert('got response from server, updating page with ' + data);});//output.innerHTML = data;});//chater.value = data;});chater = data;});//if (chater.val() == "") {//alert("no info");//} else {alert(chater.val());//}//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);} Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2012 Share Posted May 19, 2012 again chater.val() '.val()' refers to the value of form input, as before, chater is not a reference to input, its just a variable to store returned value, SO it should just bealert(chater); Link to comment Share on other sites More sharing options...
westman Posted May 19, 2012 Author Share Posted May 19, 2012 alert(chater);still a no go when i use var chater = "nnnnnn"; at the start i can see my alert box showing nnnnnn Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2012 Share Posted May 19, 2012 (edited) Sorry the problem is the alert is outside the function it will never show alert there is no alert to trigger from inside the $.post function ON the first ALERT function otoload() { var oto_update = <?php echo $id ?>;var url = "../oto_work.php"; $.post(url,{ oto_update: oto_update } , function(data) {chater = data;alert(chater);}); ///alert(chater); otoload_timer = setTimeout("otoload()",10000);} Edit: got me adding .val() now Edited May 19, 2012 by dsonesuk Link to comment Share on other sites More sharing options...
westman Posted May 19, 2012 Author Share Posted May 19, 2012 thank you so much,with your help i got this fear... window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";//var chater = "nnnnnn";$.post(url,{ oto_update: oto_update } , function(data) {//alert('got response from server, updating page with ' + data);});//output.innerHTML = data;});//chater.value = data;});chater = data;//alert(chater);//});if (chater == "") {alert("no info");} else {alert("we have info");}});//alert("Page is loaded");otoload_timer = setTimeout("otoload()",10000);} so fear so good thank you. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 19, 2012 Share Posted May 19, 2012 I think you are looking for var chater="";window.onload = otoload;function otoload() {var oto_update = <?php echo $id ?>;var url = "../oto_work.php";$.post(url,{ oto_update: oto_update } , function(data) {chater = data;});if (chater == "") {alert("no info");} else {alert(chater);}otoload_timer = setTimeout("otoload()",10000);} Link to comment Share on other sites More sharing options...
westman Posted May 19, 2012 Author Share Posted May 19, 2012 omg that works too. thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now