?
Solved

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

Posted on 2010-01-12
9
Medium Priority
?
224 Views
Last Modified: 2013-12-13
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
Comment
Question by:jen_s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 17

Expert Comment

by:houssam_ballout
ID: 26297930
can you paste the code!?
0
 

Author Comment

by:jen_s
ID: 26297987
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
 
LVL 82

Expert Comment

by:leakim971
ID: 26298295
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jen_s
ID: 26298342
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
 
LVL 82

Expert Comment

by:leakim971
ID: 26298440
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
 

Author Comment

by:jen_s
ID: 26298736
On the second page, could I run a perl script when it loads getting the cookie information then emailing it?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 26298770
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
 
LVL 8

Assisted Solution

by:albacom
albacom earned 1000 total points
ID: 26346778
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
 
LVL 82

Expert Comment

by:leakim971
ID: 26349120
Thanks for the points! Happy new year!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question