...

View Full Version : need help with if statement



maluch
08-07-2008, 10:26 PM
I am trying to check for a javascript condition and then depending on that execute a php code. My code:




<script>
var temp = 'wtf';

if(temp != 'wtf') {
<?php
$some = 'xxx';
?>
}
</script>


so i quickly learned that the php code will be executed regardless whether or not the javascript condition is met. is there a way to work around this? maybe someone can show me how to pass strings from javascript to php without forms.... thanks a lot.

ninnypants
08-07-2008, 11:05 PM
You'll have to use an AJAX request. You will still have your if statement but inside will be an AJAX function that will retrieve the information from a php page.

maluch
08-07-2008, 11:15 PM
can you provide me with sample code? thanks.

maluch
08-08-2008, 12:59 AM
anyone? project is due tomorrow at 1pm. procrastination is a killer.....

ninnypants
08-08-2008, 01:03 AM
function ajaxFunction()
{
function getInfo(){
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
xmlHttp.open('GET','page url',true);
xmlHttp.send(null);
if(xmlHttp.readyState == 4){
//what you want it to do with the response goes here
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum