Page 1 of 1

Calling PHP function onClick

Posted: Tue May 22, 2007 8:54 pm
by victorsk
Hello folks,

I am a total PHP newbie and need to figure out a way how to invoke a PHP method when user clicks a button. Here is my code for this:

Code: Select all

echo '<img src="http://10.242.225.201:8080/spacer.gif" height="0" width="400"><input type="submit" name="TourSubmit" value="Add to cart" onClick="CheckTourAvailability('.$val->outputIndex.')">'
I absolutely must use objects within the same file because these objects are used to invoke CheckTourAvailability SOAP API using the parameter $val->outputindex. To make things more complicated, I must also pass JavaScript form values obtained from drop down listboxes like this: mainform.listbox1.value and $val->outputIndex.

Right now I am using embedded JavaScript function CheckTourAvailability() that does window.open('file2.php?parameters=values) but when file2.php loads it does not have the object I need in file1.php and using include() in previous thread doesn't seem to work because it causes file1 load and file2.

All I need to find out is if I can call PHP function 'onClick' and pass Javascript values to it.

Thank you,
Victor.

Posted: Tue May 22, 2007 9:27 pm
by feyd
Nope. Not without more help from Javascript.

Posted: Wed May 23, 2007 12:04 am
by PHPycho
PHP cant be envoked on click events, Rather use javascript which in itself may contain the PHP functions..

Posted: Wed May 23, 2007 4:37 am
by thiscatis
Ajax anyone?

Posted: Wed May 23, 2007 4:59 am
by phpdevuk
explaining ajax to a newb as just "ajax" maybe a bit pointless, lol
you can basically call another php script with a function in to aquire the desired result using javascript to fetch the results.
http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX