Urgent!!! How to execute javascript function in php script

I have a javascript which, onClick for the submit button, it will store FORM information into a cookie.  I also need to send an email using the PHP script.  How do I go about doing this?  

If I change the button name to submit, the php script will execute but it ignores the "onclick" to execute the javascript function.
jen_sAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

houssam_balloutCommented:
can you paste the code!?
0
jen_sAuthor Commented:
I'll post parts of it....


<form method="post" action="/cgi-bin/mailer_teleseminar.cgi">
<input type="hidden" name="required" value="First Name">
<input type="hidden" name="required" value="Last Name">
<input type="hidden" name="required" value="Company">
<input type="hidden" name="required" value="Email">
<input type="hidden" name="required" value="Phone">

<TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="3">

<TR>
<TD class="orange" width="15%"><span class="text-medium"><B>First Name*</b></span></td>
<TD  colspan="3" CLASS="white"><input type="text" name="First Name" size="35"></td>
</tr>
<TR>
<TD class="orange" width="15%"><span class="text-medium"><B>Last Name*</b></span></td>
<TD  colspan="3" CLASS="white"><input type="text" name="Last Name" size="35"></td>
</tr>
<TR>
<TD class="orange" width="15%"><span class="text-medium"><B>Company*</b></span></td>
<TD  colspan="3" CLASS="white"><input type="text" name="Company" size="35"></td>
</tr>
<TR>
<TD class="orange"><span class="text-medium"><B>Email*</b></span></td>
<TD  colspan="3" CLASS="white"><input type="text" name="Email" size="35"></td>
</tr>
<TR>
<TD class="orange"><span class="text-medium"><B>Phone*</b></span></td>
<TD  colspan="3" CLASS="white">
<span class="text-small">Please include area code:</span><br>
<input type="text" name="Phone" size="35"></td>
</tr></form>
<tr><td colspan="4" class="orange"><span class="text-medium"><B>Select 4, 8, or all 12 teleseminars:</B></span></td></tr>


<input type="button" value="Submit" onClick="calculateTotal(this.form)">
In this function - it stores information in a cookie - then goes to orderform1.html

var seminars_string = "";
      function storeSeminar(new_item){
      seminars_string = seminars_string + "xxx" + new_item;
      document.cookie = "seminars=" + escape(seminars_string);
      }//ends function

      function calculateTotal(f){
      var total=0; var cost=0;
      var semBox=f['seminar[]'];
      alert('You selected  boxes.');
      alert('You selected ' + semBox.length + ' total ' + total + ' boxes.');

      for(var i=0;i<semBox.length;i++){
            semBox[i].checked?total++:null;
            if (semBox[i].checked)
                  storeSeminar(seminarArray[i]);
      }

      window.location.href = "orderpage1.htm";
}
0
leakim971PluritechnicianCommented:
Hello jen_s,

PHP run before you see the page on the server page
Javascript run when you see the page on the client/browser side.

Javascript don't run in PHP code but in the page generated/compiled by PHP when it come on the PHP page.


Regards.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

jen_sAuthor Commented:
Okay - if there is  a way -

This line will run the script.
<input type="submit" value="Submit">
 
I need to run this javascript function prior to the script.
0
leakim971PluritechnicianCommented:
No way :
Client side vs Server Side.

You may create a page before to do what you want and onclick open your php script/code/page

Or convert Javascript code to PHP... if possible...
0
jen_sAuthor Commented:
On the second page, could I run a perl script when it loads getting the cookie information then emailing it?
0
leakim971PluritechnicianCommented:
run a perl script on the client side ? No... On the server side, yes. But your cookie is on client side.

You should think differently and revise your process.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Altin BardhiSoftware EngineerCommented:
function your_funk(){

//Run your js code. Must be error free

//validate your code if ok then submit

if (ok){
document.your_form.submit();
or
document.getElementById('your_form').submit();
}else{
alert('There was an error. please try again');
}

}

//prior to the submit button you need to have one hidden input in order to check if it is set before you run a php script like:

<input type="hidden" name="submitted" />

<input type="button" value="Submit" onclick="your_funk()">
or
<a href="#" name="submit" id="submit" onclick="your_funk()">


if(isset($_post['submitted'])){
//Your php code

}
0
leakim971PluritechnicianCommented:
Thanks for the points! Happy new year!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.