Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

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.
0
jen_s
Asked:
jen_s
2 Solutions
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
albacomCommented:
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now