View Full Version : Is thr any way to run php script on click of javascript??

08-20-2010, 08:51 PM
Hey all

I am not that much good in JS and J* kind of thigs ..
help me out on this ..
I am opening a Dhtmml poopup ,and it's having two buttons
say YES and NO

if user click on YES
(mysql table) field say Yes should increse
else if No
(mysql table) field No should increse

I hope understand the problem
bascically on onclick I m using "window.open "
a phpFile which is updating this all ..

but I dont want to do this with window.open

any help would be appreciated

Old Pedant
08-20-2010, 09:26 PM
Yes, use AJAX.

Of you could just post to a hidden <iframe>. That's even simpler.

Maybe something like this:

Your DHTML popon DIV:

<div ...>
<form action="recordAnswer.php" method="post" target="hiddenFrame">
<input type="submit" name="answer" value="Yes"/>
<input type="submit" name="answer" value="No"/>

(Naturally, you can have other stuff in the <div>. But just so long as you have that minimal <form>.

And then, at the bottom of your page perhaps, you add:

<iframe name="hiddenFrame" style="width: 100%; height: 200px; display: none;"></iframe>

While you are DEBUGGING, you can change "display: none;" to "display: block;", so that you can see what your PHP page ("recordAnswer.php") is posting to the iframe. Makes it easy to fix problems. Then just change to "display: none;" when you are ready to go live.

Your PHP page is of course very simple:

if ( is_set($_REQUEST["answer"]) )
if ( $_REQUEST["answer"] == "Yes" ) {
$sql = "UPDATE yourtable SET yes=yes+1";
} else {
$sql = "UPDATE yourtable SET no=no+1";
// for debugging purposes!!
echo "SQL: " . $sql . "<br/>\n";

... execute the sql ...

} else {
// more debugging!
echo "Got to answer page but with NO ANSWER chosen!<br>\n";

08-20-2010, 09:52 PM
oh thanks

I will have to check what ur script is saying
but got the answer
whatI did , I just AGAIN open one more DHTML popup
like this
function YES()
var newWin1 = dhtmlwindow.open('email_friend', 'iframe', 'xxxx.php?yes', 'Coup On', 'width=0px,height=0px', "recal")
parent.newWin.close() ;


Old Pedant
08-20-2010, 09:59 PM
That works, but it's more obtrusive. The user sees the thing open briefly then go away.

Note that dhtmlwindow.open(), when used with a URL like that, is *also* using an <iframe> to hold the results from the PHP page. So, really, it's completely equivalent.

My answer is really doing the same thing, but without showing anything to the user.

09-01-2010, 11:56 PM
window.open("coupon_print_update.php?print1=1", "_self");
parent.newWin.close() ;

which is closing currnetly open DHTML

all things are woring fine , except it is tkaing little time to close in mozilla

any ideaa ??


Old Pedant
09-02-2010, 12:11 AM
Pull the same trick: Open into a *HIDDEN* <iframe> instead.

<a target="HiddenFrame" href="coupon_print_update.php?print1=1">print coupon</a>
<iframe name="HiddenFrame" style="width: 100%; height: 300px; display: none;"></iframe>

Again, that nice thing about this is that you can change "display: none;" to "display: block;" while you are developing it and see the PHP page appear in the <iframe>. Makes it easier to debug. Once it all works, change it back to "none" and the user sees nothing.

09-02-2010, 12:18 AM
gr8 work can we put ur code insode JAVASCRIPT .. not sure

but I got the solution
parent.newWin.close() ;
window.open("coupon_print_update.php?print1=1", "_self");

it is working fine on both browsers

09-02-2010, 12:34 AM
I am opening DHTML popup and it is having two buttons print and "no"
on click of print it increament the yess filed of the table
close that DHTML popup
print that page

and same thing is happenig w/o printing with no buttons