Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change variable in the middle of a page.

Status
Not open for further replies.

bdichiara

Programmer
Joined
Oct 11, 2006
Messages
206
Location
US
I need to change a variable in an Ajax situation that displays my Result message to the user. What i'm doing is performing an Ajax function, then checking a variable to see if I should show the message or not. I only want the message to show if the Ajax request completed without errors. That is, it's a form and there were no validation issues while processing, and the information got saved.

i tried
Code:
<script type="text/javascript" language="javascript">setProceed(true);</script>
and
Code:
var proceed = false;
function setProceed(towhat){
	proceed = towhat;
}

that's not working. I even tried simply
Code:
<script type="text/javascript" language="javascript">proceed = true;</script>
and that's not working. Lastly I tried:
Code:
<script type="text/javascript" language="javascript">proceed = true; alert(proceed);</script>
and that never alerts me.

I need to figure out how to change the var proceed somewhere on my PHP processing page. Any ideas.

btw, i even tried something as crazy as using a session variable to change, but it still didn't work:
Code:
var proceed = false;
function updateProceed(){
	if(<?php echo $_SESSION['proceed']; ?>){ //this gets set to true in my PHP page.
		proceed = true;
		<?php $_SESSION['proceed'] = "false"; ?>
	}
}

_______________
_brian.
 
What are those things in the code-tag? Are they the responseText you mean?

If yes, you have to do quite a few things and it is not trivial if you don't know.

[1] Insert it into the body _compiled_.
[2] In order being _compiled_, you have to use insertAdjacentHTML (and slightly more elaborated lines equivalent to ie-proprietary insertAdjacentHTML, using prototype to build it.)
[3] To provision the possibility of repetitive xmlhttp call, you have to provision some script line to remove that script-section, if exists, before insert it. To do it, contain it with some div. A fixed id should be assign to it for quick referential to it.

There are some very essential detail to take care of the script passed like that

[4] Add defer attribute to it.
[5] Add some nonempty tag like
[tt]<span style="display:none;">&nbspl</span>[/tt]
before the <script> within the <div id="xmlhttp_id"> I mention in [3].

The above involves some very tricky detail.

For simple thing like changing a global variable, you can simply responseText a single string true/false. And then in the client-side function capturing the responseText, add a line of inline compilation:
[tt]eval("process=" + oxmlhttp.responseText);[/tt]
and you're done.
 
I was thinking of doing something similar to what you're talking about. For any of my AJAX requests that require "validation" or some sort of "middle-step", I would perform 1 AJAX request to a validation page, and it would return either a true or false, then I would just do what I needed to do afterwards...

Thanks for the help.

_______________
_brian.
 
If you want aj, there is an aj forum. They need real question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top