Jump to content

calling javascript from php


Recommended Posts

I define a Javascript in the <head> section of a .php file and call it from the <body> section with the following:

echo "<script language='javascript'>function();</script>".

The function displays a confirm box with the normal Cancel and OK buttons just fine, but I want to capture the function return of true or false for which button was selected.

So far I haven't found a way to get return a value from the function. Any ideas???

Link to comment
Share on other sites

I'm assuming that you're going to be sending this to a script on the server itself, yes? If so, you can probably write some javascript that would add the return value to a hidden form value and then submit the form, which can then process.

Link to comment
Share on other sites

I wasn't looking at it that way. My flow is like this:

As stated, the function is in the <head> section of the file. A form is displayed and if the submit button is selected the page reloads itself. If  isset($_POST['submit'] is true certain fields are checked for being blank. If they are, an alert box is displayed and the form is re-displayed with the data that has already been filled in. If the fields are not blank processing continues and later in the process flow a database is going to be updated. At this point I want to call a confirm function to display a confirm box and need the response of either OK or Cancel to either continue the update or re-display the form.

Does this make sense?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.