When you say that you want to submit it "without clicking the submit button" do you actually just mean that you want to submit it without leaving the current page?

If not, then on what basis do you want to submit that data? On page load? On a timer value? Please specify.

If what you mean to say is that you want to submit without leaving the current page then this is an AJAX project. Is there any particular reason that you *have to* submit the data to the same page or can you submit it to a separate handler page that returns only the results you need (as opposed to returning the entire page's code all over again)?

In either case, what you will need to do is use javascript's http request to send the data to the server. These pages will provide some basic guidance:

Again the value for name is actually populated from ajax. And in the html rendered form the name='clientid would be name= dg9642. It is this (dg9642) that I want to pass to php without reloading the page.

I hope this makes some sense...

Rowsdower!

12-21-2010, 07:53 PM

OK, so you truly don't want the user to have to press ANYTHING before this data is sent to the server? Do I understand that correctly?

I'm really confused. If your name attribute is generated by the server and then sent to the user but NOT ever submitted later on in the process, then why not just update the $_SESSION variable with the value during your initial AJAX call and skip the second AJAX call completely? Or am I way off track for what you're doing?

My head hurts...

mbarandao

12-21-2010, 08:25 PM

I appreciate the reply --my apology for the head pain. As I'm new to much of this and Learning on the fly, what you write may be on track in relation to my need. I've been trying to accomplish this for some days now and I'm at my wits-ends. I suspect that you have an understanding of my situation... If, I may, let me strengthen my explanation.

The form is a client look-up application. The user enters a value in one field and on onkeyup the rest of the data is populated --via ajax. This process works fine!

I have made the task a bit more complicated by adding an image display in the form; whereas the image is retrieved from both a directory(image data) and mysql(image name) and displayed in the form based. The variable used to retrieve the name of the image from db is the value of one the form input (ie: <input type="text" style=background:transparent; border:0px; name='clientid' >). The php code is for this purpose.

I know this maybe a bit unorthodox, but I see no other way of achieving this task.

Rowsdower!

12-21-2010, 09:02 PM

What you are describing sounds like a "personal image" (or whatever they call them) that some sites use during user authentication. In general the user enters their username and submits, then the server sends a response to set up a password field and displays that user's "personal image" so that the user can be assured that they are truly accessing the intended site as opposed to a phishing site.

If this is something like what you are trying to do, and if you want to display that image without giving away the file's location then what you can do is set up a PHP page, say "image_display.php" and then use that file - along with any necessary $_GET variable string - as the image's src attribute.

Then, in "image_display.php" you have a MySQL hook to look up the path to the user's selected personal image. Once located, the image_display file can send header text and send the file contents of the image directly, which means that the user never sees the actual filepath.

Is this something like what you are talking about?

mbarandao

12-21-2010, 09:17 PM

Actually, what you describe is not the samething I'm doing. Here is my entire code for what I'm doing... see if it makes sense to you.

I guess my question is still this: why does the AJAX call have to be made to this same page?

If you understand event handlers and how to make AJAX requests (and it seems as though you do), then all you really need to do in this case is set up a separate PHP page to hit with your second AJAX request so that it returns only the image source that you are looking for. Then you just store that response as a variable and set your image src equal to that text string.

If I understand the pieces of your code that I have, then this will basically consist of taking this part:

// and, *IF* you need these for other purposes:
//$clientID = $get_data_info["clientid"];
//$platenumber = $get_data_info["clientid"];
// but don't bother with them if you don't need them!

//echo '<image src="' . $uploadedfile . '" />'; // OR SIMILAR!!

print $uploadedfile; //This is all you need to do to have the AJAX request send the file source to the user...
//You should probably check to make sure that the file exists on your server before you try to send that image source to the user. Otherwise, they will get a blank box from a missing resource.
//You might also want to set up a default image and then, if no database results are returned, present that image source to the user rather than a blank source which would also create a "missing image" box in the page.

}
}
?>

And plopping it into a separate file and using AJAX to send variables there for processing. Unless it is already part of datalogin.php you will of course have to add some code to the PHP above to handle your $_POST or $_GET variables, whichever is appropriate for your approach.

Your problem right now appears to be that you are trying to get your javascript to talk to your PHP in some cases while the page is still loading - which doesn't work. You will need to set the initial page load up to send no image or a default image for "uploadedfile" and then change the source code with an AJAX request to a page other than this same page you are viewing. Technically you could hit the same page with the AJAX request, but the coding to differentiate between a basic page load and an AJAX request - and then filtering what you return to the browser based on that difference - is not worth your time. Just make the image checking script on a different file and hit that instead.

I should also mention that you seem to have quotation marks out of order on some of your attributes. Most notable for me was this case: