Jump to content

Archived

This topic is now archived and is closed to further replies.

jasonc

execute php from javascript

Recommended Posts

I have a form that is filled in and each part that has something done to it i want added to a database on my server, for that user.

I have a onchange=update() in my form and this would then call the script to update the database.

is this possible.

or is there another way i can do this.

i tried to use in the update.js file


function update()
{
<?
echo("hello");
?>
}

just to see if anything happen, and it did not.

how can i execute php while in a js file?

is there another way to do this?

thanks you in advance for your help.


Jason

Share this post


Link to post
Share on other sites
php is executed on the server and then the code that is outputted by the php code, is added to your site's HTML. After a user views your website, the php has already been executed and the output writen to your site. If you need to pass information to a php file after the user has viewed your site you can set up a hidden or visible textbox form with HTML, and send the POST values (or the values of each form element after the user has 'posted' the form) to another php file.

Set your form "action" to the next php file you want to pass the variables to, and then you can use $_POST['html form element name'] THis is your form element value.

Share this post


Link to post
Share on other sites
You can now use the new(ish) AJAX techniques to do this. There is a forum on this site for AJAX questions along with a sister site [a href=\"http://www.ajaxfreaks.com/\" target=\"_blank\"]AJAXfreaks[/a].

Ken

Share this post


Link to post
Share on other sites
my page has lots of options and i want to be sure that the selection are kept in case they lose their connection of what ever.

each person has a login name and password.

while they make their selection i want the database updated on each change, so that they can come back later to finish off, without having to full out everything from the start again.

how else can i do this?

Thanks

Jason

Share this post


Link to post
Share on other sites
Use javascript to store the values in a cookie.

[a href=\"http://www.w3schools.com/js/js_cookies.asp\" target=\"_blank\"]http://www.w3schools.com/js/js_cookies.asp[/a]

Then when they come back to the site, you should be able to retrieve the vars in either php or javascript.

Share this post


Link to post
Share on other sites
Hi,

Thanks for a quick response.

Yes i know i could use cookies, but want to make this as streamlined as possible.

i know as i do myself, disable cookies from being stored on my pc, this is why i would like to have it stored in the database.

how else can i do this?


Jason

Share this post


Link to post
Share on other sites
[!--quoteo(post=349702:date=Feb 27 2006, 12:00 AM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Feb 27 2006, 12:00 AM) [snapback]349702[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Your only other option for storing each field as they are entered is ajax.
[/quote]

your say ajax, but what am i looking for?

i have posted my question there.

thanks

Jason

Share this post


Link to post
Share on other sites
[!--quoteo(post=349788:date=Feb 27 2006, 09:53 AM:name=tim_perrett)--][div class=\'quotetop\']QUOTE(tim_perrett @ Feb 27 2006, 09:53 AM) [snapback]349788[/snapback][/div][div class=\'quotemain\'][!--quotec--]
AJAX it is, thats the only way you will do that....

www.ajaxfreaks.com

Tim Perrett
[/quote]

ajax is a forum with some help pages with scripts.
what an i actually looking for on this site.
a link would be helpfull to an idiot like me.
i am not very bright!

Share this post


Link to post
Share on other sites

×

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.