Jump to content

I have nearly got this solved.. i am grasping my Q&A and need lead to result


Recommended Posts

Hello.

I want to get the server ajax request and turn it into a variable which i can use in If statements.

 

FOR EXAMPLE:

<?php
some php code here, mostly some calls to ready made functions
?>
//this is part of our ajax/javascript calls and html form (I got this example from the net)

ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
// here we say to put the ajax responce into a id with name time.. as value..blah blah 
		document.myForm.time.value = ajaxRequest.responseText;
	}
}
ajaxRequest.open("GET", "serverTime.php", true);
ajaxRequest.send(null); 
}
//here is the actual form
//-->
</script>
<form name='myForm' method="post">
Name: <input type='text' onChange="ajaxFunction();" name='username' /> <br />
Time: <input type='text' name='time' /> //here is the id(or name) time where the ajax responce is used as value ...
</form>
</body>
</html>

//HERE IS WHERE MY QUESTION LIES: 

<?php

If this was all php without ajax i would submit the form to self, the page would reload and my post/get would be picked up, and i could use them in if statements like so:

if ($_GET['time'] == '12:00'){
$thedaytime='Afternoon';
} else {
if ($_GET['time'] == '18:00'){
$thedaytime='Evening';
} else {
if ($_GET['time'] == '00:00'){
$thedaytime='Its past your bed time';
}
}
}
?>

HERE IS MY QUESTION!!!!!

How can i Manipulate the "echo" result that i get from a ajax response so that i can change it into a variable so that i can use them in the if statements like the example above???

something like so:

if (echo result of ajax  == '00:00'){

$thedaytime='Its past your bed time';

}

 

any help!

best regards

Tony

 

 

You will not be able to use the if statement example you gave us because it's php. And yes I know that you knew that. :D

 

Change this line

document.myForm.time.value = ajaxRequest.responseText;

 

Call the function that will do the if statements. Let's call that function iffy(time)

 

iffy('ajaxRequest.responseText');

 

Should do the trick.

 

 

Hi sunfighter,

Thanks for the response....

 

The direction you are taking me, although 100% on the right track, is way on the other-side of what i had in my mind.. ;D

 

I see where you going now...

could you give me an example of the "iffy" function? Like just a small complete function example? and would this function be in .php or javascript?

 

 

 

Hi, Im back i did some more research for examples based on what you showed me.. I again viewed 60++ email form examples, a couple of login examples a couple of validation scripts, but i cant find what im looking for!!:

 

I dont think Ajax can help me! or ...?

 

All ajax does is give a responce to your input! or validate thats all i find validation and email...

 

I havent found one single example for what i need. And to me it seems like something that should be basic to do!!!

Here is a working sample of my current code: (WHICH IS PHP) all im trying to do is! make it so that the page does not reload!

SEE below

 

//heres my form
		<div><form method="post" action="#" name="presearchform" >
		<center><table width="50%" style="border:1px solid #444444">
		<tbody><tr><td colspan="1">Gender:</td><td colspan="1"><select name="searchgender" id="searchgender" class="inputbox">
		<option value="Male">Male</option>
		<option value="Female">Female</option>
            </select></td></tr><tr><td colspan="2" style="text-align:right"><input type="image" value="Submit" name="Submit" alt="Submit" src="search.png">
<input type="hidden" value="1" name="postintegratedsearch"></td></tr>			
</tbody></table></center>
</form><br></div>


//heres the php part

<?php
		if ($_POST['postintegratedsearch'] == '1')
			{
			blah blah blah
			}


			If ($_POST['searchgender'] == 'Male'){

			blah blah blah
			}

//			anf then further down i may have another

			If ($_POST['searchgender'] == 'Male'){

			blah blah blah
			}

//			and then another but this one will be for female!!


			If ($_POST['searchgender'] == 'Female'){

			blah blah blah
			}
?>				

 

How would i use the example you gave me to make this work for example?

 

If ($_POST['searchgender'] == 'Male'){

 

blah blah blah

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.