...

View Full Version : xmlhttp.open() target the same page



mbarandao
02-17-2011, 06:56 AM
I need some help getting the included ajax script's xmlhttp.open() to target a php code within the same page --something like $_SERVER


here is the script:
[PHP]
<script type="text/javascript">
function showResult3(strss)
{
if (strss.length==0)
{
document.getElementById("livesearch3").innerHTML="";
document.getElementById("livesearch3").style.border="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch3").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch3").style.border="1px solid #A5ACB2";
}
}

xmlhttp.open("GET","q="+strss,true);//$_SERVER[PHP_SELF]
xmlhttp.send();

}
</script>

I want to pass the variable $q to a php code in the same page as the code above. I know typically the xmlhtpp.open() need a url which tent to be an external one. I'm hoping that there is a work around.

I appreciate any help!

venegal
02-17-2011, 04:40 PM
The window.location object contains all the information you need.

mbarandao
02-17-2011, 06:16 PM
not quite clear of window.location implementation in the xmlhttp.open() based on some docs i have read so far.

If the page in which my ajax function showResult(str) is to send the $q variable to the php code is "client_info.php", then how do I implement the window.location object to


xmlhttp.open("GET","?q="+str,true);
xmlhttp.send();

venegal
02-17-2011, 07:14 PM
Here's some documentation: https://developer.mozilla.org/en/DOM/window.location

Since you want the current URL without the querystring (because you add that manually), the "pathname" property is probably what you're looking for.

So, something like this:

xmlhttp.open("GET", window.location.pathname + "?q=" + str, true);

mbarandao
02-17-2011, 09:42 PM
No success in passing $q within the same page. I modified like this



<script type="text/javascript">
function showResult3(strss)
{
if (strss.length==0)
{
document.getElementById("livesearch3").innerHTML="";
// document.getElementById("livesearch3").style.border="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch3").innerHTML=xmlhttp.responseText;
//document.getElementById("livesearch3").style.border="1px solid #A5ACB2";
}
}
//xmlhttp.open("GET", window.location./i-cmsys/ + "?q=" + strss, true);//the actual path, also with no success
xmlhttp.open("GET", window.location.pathname + "?q=" + strss, true);
xmlhttp.send();

}
</script>

venegal
02-17-2011, 10:09 PM
Well, debug the thing!

What's

window.location.pathname + "?q=" + strss
?

Alert it and have a look!

What is it supposed to be, and why is it different?

Those are things you have to be able to ask (and answer) yourself, if you want to be able to get something working without the help of others (whose job is considerably more difficult than yours, because they don't see all of your code).

mbarandao
02-17-2011, 10:19 PM
Well, I have been debugging and still at it. Just posted the code for another set of eyes for something I maybe missing.



//xmlhttp.open("GET", window.location.pathname + "?q=" + strss, true);


I meant to comment this line out when I posted --I used it inside the code for guidance purpose only. It is commented out in the actual code.

Since there are no errors being reported, it is a bit more of a challenge.

venegal
02-17-2011, 11:27 PM
I don't know what you mean by "debugging", but I mean exactly what I said before:

Alert the thing, tell us what it is, and tell us what it's really supposed to be. There's no way to help you otherwise.

Also, if that line is commented out in your actual code, that means that you don't have any xmlhttp.open() command in your code at all, so it's no wonder it does nothing.

mbarandao
02-17-2011, 11:49 PM
xmlhttp.open("GET", window.location./i-cmsys/client_information.php + "?q=" + strss, true);


when I alert the page it shows the correct path as in above

venegal
02-18-2011, 12:09 AM
xmlhttp.open("GET", window.location./i-cmsys/client_information.php + "?q=" + strss, true);


when I alert the page it shows the correct path as in above

Well this is certainly not a correct path. It isn't even a string, it's just a sytax error.

You're a bit hard to help, because you don't really tell us the relevant stuff.

1.) If, instead of the window.location.pathname thing, you put in the real URL, does it work? I suppose so if not, that's a completely different problem. Please post that line with the real URL in it.

2.) Assuming, it works, with the real URL put in, change it to the window.location.pathname one. If that now doesn't work, see if it evaluates to anything different than the real URL. Please post what it evaluates to.

mbarandao
02-18-2011, 01:45 AM
My apology, I was of the notion that I was answering your questions fully --but my mistake.

I'll follow you last advice and note back shortly!

Thanks for the continued help.

devnull69
02-18-2011, 08:51 AM
Again ... most certainly mbarandao seems to be consumed by the common misunderstanding that you can indeed influence the already executed PHP from Javascript. I conclude this from his question ... "I want to pass the variable $q to a php code in the same page as the code above".

Passing "?q=" from Javascript to the PHP that originally created the current page will never end up on the same page ... it will be on a new page that has been created using the same PHP file. You can indeed process the result of the newly created output from the PHP using Javascript and assemble it into the current page though

But we will see ...

venegal
02-18-2011, 09:21 AM
Again ... most certainly mbarandao seems to be consumed by the common misunderstanding that you can indeed influence the already executed PHP from Javascript. I conclude this from his question ... "I want to pass the variable $q to a php code in the same page as the code above".

Well, the AJAX callback is all set up to add the response to the DOM, so I don't think that that's the problem.

mbarandao
02-18-2011, 04:13 PM
hello,

it appears that using the following:


var url = window.location.pathname + '?q=' + strss;
alert(url);//to inspect the url string.
xmlhttp.open("GET", url, true);
xmlhttp.send();


puts me in the right direction for this task of mine. However, I'm still facing some difficulties.

There is definitely progress with this last solution. However, when the alert appears --displaying the correct path and the correct $q variable, after click the ok button, a duplicate of the same page loads at the bottom. I have echo'ed the $q inside the php code, it only appears in the duplicate page --this obviously is not something I want.

Nothing happens when I comment out the alert(url);

any ideas?

venegal
02-18-2011, 05:58 PM
You, sir, are really difficult to help. Just like I said before:

1.) If, instead of the window.location.pathname thing, you put in the real URL, does it work?

I suppose it doesn't, because you say alerting that generated URL shows that it's correct. If that's really the case, this is a completely different problem, because your server doesn't seem to return what you expect it to return.

Btw, if you don't have your server script set up to not build a whole page if that "q" parameter is set, it's obvious, too, that the whole page will be loaded and put into the current page.

Also "Nothing happens when I comment out the alert(url);" sounds like you're doing something wrong. If that's really the case, that means that you have a race condition in there and probably call showResult3 before the page is fully loaded. Since you never cared to share with us, how and when you call that function, there's no way to know.

Anyway, you seem to be in way over your head with a rather general problem, yet you're only talking about a very specific one, which should have been solved by my first post.

Either you post a link to your site and start to really explain what you want (generally, and in plain english), or, I'm afraid, you won't get any advice that really helps you get this working.

mbarandao
02-18-2011, 07:09 PM
venegal, thanks for the post. OK!

I would like to either post my entire code or provide a link, but two issues.

1.) the entire code is about 900 lines --which I think would deter others because of the lenght.
2.) the project I'm working on is for a local intranet network; therefore I cannot post a link publicly. If there is a private platform on which I can post the link, I'll be glad to do so.

Starting from my intended goal --though maybe considered "illogical", it is the best option I'm prevy too at the moment.

On the current page, a client LookUP form is populated by an ajax code. This code takes its initial value from an input box on the form "clientID". This is the code:


var ajax = new sack();
var currentClientID=false;
function getClientData()
{
var clientId = document.getElementById('clientID').value.replace(/[^0-9|a-z|A-Z]/g,'');//here to incorporate the client id with numbers and letters
if(clientId.length >0 && clientId!=currentClientID){//here to change the client id lenght
currentClientID = clientId

ajax.requestFile = 'getClient.php?getClientId='+clientId;
ajax.onCompletion = showClientData;
ajax.runAJAX();

}

}

function showClientData()
{
var formObj = document.forms['clientForm'];
eval(ajax.response);
}


function initFormEvents()
{
document.getElementById('clientID').onblur = function(){getClientData();
}
document.getElementById('clientID').focus();
}



Now this ajax has a companion external php file which processes and retrieves necessary form fields and returns the values back to the form. this is the php:


$res = mysql_query("select * from additional_cars where clientID='".$_GET['getClientId']."'") or die(mysql_error());
if($inf = mysql_fetch_array($res)){
echo "formObj.firstname.value = '".toSafeString($inf["firstname"])."';\n";
echo "formObj.lastname.value = '".toSafeString($inf["lastname"])."';\n";
echo "formObj.lastname1.value = '".toSafeString($inf["lastname"])."';\n";
echo "formObj.address.value = '".toSafeString($inf["address"])."';\n";
echo "formObj.zipcode.value = '".toSafeString($inf["zipcode"])."';\n";
echo "formObj.city.value = '".toSafeString($inf["city"])."';\n";
echo "formObj.state.value = '".toSafeString($inf["state"])."';\n";
echo "formObj.dhtmlgoodies_category.value = '".toSafeString($inf["dhtmlgoodies_category"])."';\n";
echo "formObj.dhtmlgoodies_subcategory.value = '".toSafeString($inf["dhtmlgoodies_subcategory"])."';\n";
echo "formObj.caryear.value = '".toSafeString($inf["caryear"])."';\n";
echo "formObj.servicedesc.value = '".toSafeString($inf["servicedesc"])."';\n";
echo "formObj.currentmileage.value = '".toSafeString($inf["currentmileage"])."';\n";
echo "formObj.servicearea.value = '".toSafeString($inf["servicearea"])."';\n";
echo "formObj.drivenmileage.value = '".toSafeString($inf["drivenmileage"])."';\n";
echo "formObj.clientid.value = '".toSafeString($inf["clientID"])."';\n";
echo "formObj.clientid2.value = '".toSafeString($inf["clientID"])."';\n";
echo "formObj.clientid3.value = '".toSafeString($inf["clientID"])."';\n";
echo "formObj.displayname.value = '".toSafeString($inf["lastname"]).",".toSafeString($inf["firstname"])."';\n";


}
else
{
echo "formObj.firstname.value = '';\n";
echo "formObj.lastname.value = '';\n";
echo "formObj.lastname1.value = '';\n";
echo "formObj.address.value = '';\n";
echo "formObj.zipcode.value = '';\n";
echo "formObj.city.value = '';\n";
echo "formObj.state.value = '';\n";
echo "formObj.dhtmlgoodies_category.value = '';\n";
echo "formObj.dhtmlgoodies_subcategory.value = '';\n";
echo "formObj.caryear.value = '';\n";
echo "formObj.servicedesc.value = '';\n";
echo "formObj.currentmileage.value = '';\n";
echo "formObj.servicearea.value = '';\n";
echo "formObj.drivenmileage.value = '';\n";
echo "formObj.clientid.value = '';\n";
echo "formObj.clientid2.value = '';\n";
echo "formObj.clientid3.value = '';\n";
echo "formObj.displayname.value = '';\n";
}

}

Now on the form, the values are not displayed as variables($), instead they are displayed as formObj value (ie: clientid).

This is where my problem begins; whereas, I want to pass the clientid as a variable to a page outside of the current thru url (ie: insertclientinfonew.php?clientid=$clientid"). But cannot do this because clientid in the current page is not a variable.

So, in my somewhat novice coder mind, I thought that if I created a php code within the same page and using ajax, pass the clientid to this code and then from there, create a variable of clientid. As you noted strongly, this seem illogical; and to some respect it is!

This is why I have come to this forum in hopes of learning from the great wisdom here!

So, if there is a simpler way to achieve this goal, based on my explanation here, please advise...

Best,
Mossa

djm0219
02-18-2011, 07:19 PM
Ajax is used to call some script on the server whether it be the same one or a different one. In your case a separate one that accept the clientid and returns it would seem to be the best choice. There's nothing stopping you from putting everything in one script but you'll find that it is easier to have a separate one (especially based on what you've described so far).

venegal
02-18-2011, 08:06 PM
Ok, I guess I'm starting to understand what this is about. You have a variable in your PHP script, and you want to access that with Javascript.

If that's indeed what you want to do, you can either make PHP write out the necessary Javascript to define a Javascript variable with the value of the PHP variable in the first place, like

<script type="text/javascript">
var myVar = <?php echo json_encode($myVar) ?>;
</script>

or you could make an ajax call for that information, and let the responsible PHP script return JSON, which you can then parse with Javascript in order to get the data into a Javascript object.

mbarandao
02-18-2011, 08:30 PM
... a bit of relief! We are somehow getting on the same page.
Just to clarify, I have a value (clientid) which is not a variable in the form, I'm trying to pass it to php as a variable.

The thing is that the form does not have a submit button --because it receives values from db in the manner mentioned in my detailed explanation.

I do not believe I can grab clientid as $clientid directly from the first php --which passes the variables to the form via ajax into my second php script that is on the same page as the form. I may be wrong; however, I trust to stand corrected, because this would resolve my issue!

Is this your understanding of my issue that predicates your suggestion in the last post? if so, I'll attempt that suggestion!

Mossa

venegal
02-18-2011, 09:07 PM
Ok, so the actual premise is that you have some value in some form input, and you need to access that with Javascript in order to pass it to a PHP script.

I don't know how your HTML looks like, but if, for example, it looks like this:

<form name="myForm">
<input type="text" name="clientID" value="something" />
</form>

you can access the actual value of the input in your Javascript like this:

var clientID = document.myForm.clientID.value;

mbarandao
02-19-2011, 04:56 AM
Thanks for the follow-up.

But I still believe my problem remains; for how do I get the variable --once I have it as js var, to the php code in the same page?

venegal
02-19-2011, 05:19 AM
Well, I suppose I just don't understand you. "The php code in the same page" doesn't really make sense there is no PHP in the page. As soon as you can speak of a "page", that is, as soon as PHP has finished its job and the generated page hits the browser, there is no PHP any more. The PHP process has died. Whatever you do then to talk to your server, it will always spawn a completely new PHP process that has nothing to do with the previous request. If you have somehow built your application around the idea that your browser can continuously talk to the same PHP process, this will never work.

Maybe I misunderstand what you are saying, and if so, I'm sorry, but even after your explanations I just don't understand the intended process flow at all.

Maybe someone else, who better understands what you're after, can chip in.

mbarandao
02-19-2011, 05:51 AM
Cool! Let me give it another shot...

The page with the form values is called client_information.php. Inside this page I have this :


<form name="clientForm" action="client_information.php" method="post"> <!--ajax-client_lookup.html-->

<!--<input type="text" id="clientid" onkeyup="showHint(this.value)" />-->
<!--<input type="hidden" style=background:transparent; border:0px; name='clientid' >-->
<fieldset style="width: 1090; height: 470">
<legend align="left"><b><font size="4" color="#FF0000">Client information</font></b></legend>

<div style= "position: absolute; width: 140px; height: 140px; z-index: 3; left: 430px; top: 230px; background-transparent:; bottom:-7" id="layer3"><!--width 140 height 140-->
<DIV style="border-style: inset;" "position: absolute; width: 104px; height: 100px; left: 4px; top: -15px" id="image" ><span id="txtHint" title="Client Vehicle"style="color:#BEBEBE" ></span></DIV>
<!--<span id="txtHint"></span>-->
<!--<image src='' border="1" width="104" height="100" name="uploadedfile"-->

&nbsp;</div>

<table width="1100">
<tr>
<td>License Plate Number:</td>
<td>
<input name="clientID" id="clientID" size="17" maxlength="16" style="background-color: #00FFFF" value="License Plate#" onkeyup="showHint(this.value)"> &nbsp;&nbsp;<!--for car image display-->
<div id="hidden" style="color:#BEBEBE" ><input type="text" id="clientid" name="clientid" size="17" onblur="showResult(this.value)"></div><!--for balance display onblur="showResult(this.value)"oninput="OnInput(event)" onpropertychange="OnPropChanged()" value=""; onblur="showResult(this.value)" -->
<div id="hidden2" style="color:#BEBEBE" ><input type="text" name="clientid2" id="clientid2" size="17" ></div><!--for Oil Change Date display onkeyup="showResult2(this.value)";-->
<div id="hidden3" style="color:#BEBEBE" ><input type="text" name="clientid3" id="clientid3" size="17" onblur="showResult3(this.value)"></div><!--for passing the variable onkeyup="showResult3(this.value)"-->
<div id="blankbox" style="color:#FF0000" ></div><!--<input style="color:#FF0000"type="text" name="none" id="none" size="17" >-->
<!--<input type="text" name="returnedClientId" id="returnedClientId">-->
<!--<input type="button" onclick="locationPathname();" value="get Location Pathname" />-->


<a class="button" href='#'><span>CLICK TO SEARCH</span></a>
</b></td>
<td>
<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<div style="position: absolute; width: 519px; height: 455px; z-index: 1; left: 610px; top: 192px; background-color:#FFFFFF" id="layer1">

<table border="0" width="100%" height="372">
<td width="50" height="25" valign="top" bgcolor="#000000" align="center"><font size="5" color=#FFFFFF>Vehicle Details<hr color="#FFFFFF" size="1"></td>
<tr>
<td height="26">
<!--<p align="center"><font size="4">Vehicle Details<hr color="#C0C0C0" size="1">-->
</font></td>
</tr>
<tr>
<td VALIGN="top" width="1%" style="border-left: 0px dotted" color="#CCCCCC;">
<div id='separating-line'></div>

<!--<p align="right"><label for="theDate">Customer Since:</label>
<input type="text" name="theDate" size="20" style="padding: 0" disabled="true"></p>-->
<p align="left">
<label for="dhtmlgoodies_category">Make:</label>
<input type="text" name="dhtmlgoodies_category" id="dhtmlgoodies_category" size="14" style="padding: 0" disabled="true">
<label for="dhtmlgoodies_subcategory">Model:</label>
<input type="text" name="dhtmlgoodies_subcategory" size="25" style="padding: 0" disabled="true">
&nbsp;&nbsp;&nbsp;<label for="caryear">Year:</label>
&nbsp;<input type="text" name="caryear" size="5" style="padding: 0" disabled="true"></p>
<label for="currentmileage">Last Recorded Mileage:</label>
<input type="text" name="currentmileage" id="currentmileage" size="20" disabled="true"><br><p>

<label for="servicearea">Last Service Rendered:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="drivenmileage">Driven Miles
</label>
<textarea name="servicearea" id="servicearea" cols=40 rows=2 style="padding: 0" disabled="true"></textarea><!--<label for="drivenmileage">Driven Miles
between the last two visits:</label>-->
<textarea name="drivenmileage" id="drivenmileage" cols=10 rows=2 style="padding: 0" disabled="true"></textarea>
<!--<input type="text" name="drivenmileage" id="drivenmileage" size="5" disabled="true">--><br>

<label for="servicedesc">Service History:</label>
&nbsp;
<!--<div id="servicedesc" name="servicedesc"></div> -->
<!--<textarea name="servicedesc" id="servicedesc" cols=60 rows=12 disabled="true" style="position: absolute; right: 13; top: 260"></textarea></td>-->
<textarea name="servicedesc" id="servicedesc" cols=60 rows=12 disabled="true" style="position: absolute; right: 13; top: 260"></textarea></td>
</tr>
</table>

</div>
</td>
</tr>


<tr>
<td><label for="firstname">First name:</label></td>
<td>
<input name="firstname" id="firstname" size="20" maxlength="255" disabled="true"></td>
<td>
&nbsp;</td>
</tr>

<tr>
<td><label for="lastname">Last name:</label></td>
<td>
<input name="lastname" id="lastname" size="20" maxlength="255" disabled="true"></td>
<input type="hidden" name="displayname" id="displayname" size="20" maxlength="255" onBlur="document.displayinfo.displayvalue.value=document.clientForm.displayname.value">
<input type="hidden" name="lastname1" id="lastname1" size="20" maxlength="255" onBlur="document.displayinfo.lastnamevalue.value=document.clientForm.lastname1.value"></td>

<td>
&nbsp;</td>
</tr>
<tr>
<td><label for="address">Address:</label></td>
<td>
<input name="address" id="address" size="20" maxlength="255" disabled="true"></td>
<td>
&nbsp;</td>
</tr>
<tr>
<td><label for="zipcode">Zip code:</label></td>
<td><input name="zipcode" id="zipcode" size="8" maxlength="5" disabled="true"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label for="city">City:</label></td>
<td><input name="city" id="city" size="20" maxlength="255" disabled="true"></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
</tr>
<tr>
<td><label for="state">State:</label></td>
<td>
<input name="state" id="state" size="20" maxlength="255" disabled="true"></td>
<td>
&nbsp;</td>
</tr>
<tr>
<td><label for="tel_number">Phone #:</label></td>
<td>
<input name="areacode" id="areacode" size="3" maxlength="3" disabled="true">-<input name="phoneprefix" id="phoneprefix" size="3" maxlength="3" disabled="true">-<input name="phonesufix" id="phonesufix" size="4" maxlength="4" disabled="true"></td>
</tr>

<tr>
<td><label for="email">Email:</label></td>
<td>
<input name="email" id="email" size="42" maxlength="25" disabled="true"></td>
<td>
&nbsp;</td>
</tr>
<tr>
<td><label for="cell_number">Alt. Phone#:</label></td>
<td>
<input name="cellareacode" id="cellareacode" size="3" maxlength="3" disabled="true">-<input name="cellprefix" id="cellprefix" size="3" maxlength="3" disabled="true">-<input name="cellsufix" id="cellsufix" size="4" maxlength="4" disabled="true"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label for="commentonclient">Special Comment on Client:</label></td>
<td>
<p align="left">
<textarea name="commentonclient" id="commentonclient" cols=36 rows=6 disabled="true"></textarea>
</tr>
<td>
&nbsp;</tr>
</table>
<div id="livesearch2" ></div><!--div for oil change-->
<div id="baldue" >Balance On Account</div><!--Label div for balance due-->
<div id="livesearch" ></div><!--div for balance due style="filter:alpha(opacity=100); opacity:0.5;">-->
<div id="oilchangedate" > Next Oil Change Reminder</div><!--Label div for oil change-->
<a id="emailicon" title="Notify Client via Text or Email Concerning an Oil Change" onmouseover="this.style.cursor='pointer'" onfocus='this.blur();' onclick="document.getElementById('PopUp11').style.display = 'block' "></a>
<div id="PopUp11" style="display: none; position: absolute; height: 400px; left: 0px; top: 150px; border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; font-size: 12px; width: 410px;">
<iframe id="mate" frameborder=0 scrolling=yes width=100% src='sms\\notifyClient.htm' height="790" align="left"></iframe><br />
<div valign="top" style='text-align: right; display: inline; position: absolute; left: 10px; top: 10px;'><a onmouseover='this.style.cursor="pointer" ' style='font-size: 12px;' onfocus='this.blur();' onclick="document.getElementById('PopUp11').style.display = 'none' " ><span valign='left' style="text-decoration: underline;" >Close Window!</span></a>
</div></div>
<div id="passingvar" ></div><!--Label div passing var to process client-->
<div id="livesearch3" ></div><!--div passing var to process client-->


<!--<div id="BalDue">Balance Due is:<span id="displayHint" style="color:#BEBEBE" ></span></div> -->

</form>
which constitute my form and is populated dynamically with one of my ajax.

Now with this same page (client_information.php) I have this php code:


<?php

error_reporting(0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'datalogin.php';

//this query pulls all client id from ajax and makes it available for ajax hint to compare with what is being inputed on the form
$result = mysql_query("SELECT clientID, customerid FROM additional_cars");
while($row=mysql_fetch_array($result)) {
$clientID=$row["clientID"];
$a[]= "$clientID";
//echo "client id is $clientID";

}
//get the q parameter f
$q=$_GET["q"];
echo "q is $q";

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
{
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($hint=="")
{
$hint=$a[$i];
}
else
{
$hint=$hint." , ".$a[$i];
}
}
}
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
{
//$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
//echo" id is $response";
$trimmed = trim($response); //trim whitespace from the stored variable

$get_swork2 = "select * from additional_cars where clientID='$trimmed'";// order by id desc limit 1";//here we are pulling dat from services where the license plate is $clientID, we use this to display last service(s) rendered
$get_swork2_res = mysql_query($get_swork2);

if (mysql_num_rows($get_swork2_res) > 0)
{
while ( $swork2_info = mysql_fetch_array($get_swork2_res))
{
$firstname = $swork2_info['firstname'];
$lastname = $swork2_info['lastname'];
$comma=", ";
$sel_id="$lastname$comma$firstname";

}
}
?>
Now this php code is intended to provide certain variables, that I can append to a link that is going from this very page. this is the link:


<a href="addentrynew_passed.php?sel_id=<?php echo $sel_id?>&lastname=<?php echo $lastname?>">PROCESS CLIENT</a>


A bit long, but I have no other way to convey this issue. I apologize for any redundancy...

Mossa

mbarandao
02-20-2011, 12:12 PM
Issue resolved!

Final solution...

Instead of trying to pass the variable within the main page (I'm calling "client_info.php) using the window.location object, I used xmlhttp.open("GET", url) and made the ajax call to the initial code I had within "client_info.php", but as an external file (and called getVariables.php). This obviously was simple and is how --I suppose, xmlhttp.open() is intended to be used. The challenge in my case was that I needed to return certain variables back to the sending page and appended those variables to a button; to therefore onclick of this button, will pass those variables in a url to the proceeding page.

Solution: I removed those links from the initial page (client_info.php) and recreated them in the ajax companion php page (getVariables.php). Using css within this page, I positioned these links inside a div with the same percise x and y cordinates to replace the initial links on the main page (client_info.php). So now, when the client's information has been retrieved and displayed on client_info.php, another ajax (function showResult()) makes a call to getVariables.php and returns the links back to the main page with the appropriate variables. Now, if clicked, the variables of that particular client are passed. That has been the goal!


Thanks for all of the thoughts on this task!
Mossa



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum