faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 8 people (25%) answered Yes
Recently 2 of 8 people (25%) answered Yes

Entry

How to return values of javascript variables to php local variable

Apr 8th, 2008 19:05
ha mo, Dave Clark, satish indi,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Satish,
     The only way to send JavaScript variable values to PHP is to 
submit these values via some form of an HTTP request.  Just off the 
top of my head I can think of at least five ways to do this:
XMLHttpRequest object (http://jibbering.com/2002/4/httprequest.html)
FORM standard submission
LINK standard navigation
IFRAME hidden navigation
IMAGE tag or object
     Note that the last one can be done within JavaScript code only -- 
but it is one-way communication (though you can get a success or 
failure indication by using the onload and onerror events, too).  For 
example:
var send = new Image();
send.onload = send_success; // your function
send.onerror = send_failed; // your function
send.src = "mypage.php?var1="+var1+"&var2="+var2+"&etc.";
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com