在javascript和php之间传递值的问题-弹出php javascript HTML

在javascript和php之间传递值的问题-弹出php javascript HTML,javascript,php,html,Javascript,Php,Html,我正在尝试将弹出窗口合并到我的项目中。直到我尝试将一个值从javascript传递到php脚本,它才会停止工作。我已经包含了一个指向我使用的示例和原始脚本的链接。对原始脚本做了一些细微的修改。我遇到问题的区域标记为----> 完整脚本可在此处找到: 可在此处找到工作示例: 我在hello.html中有以下内容 <form id='form1' style='width: 1100px'> <table> <th>Email</

我正在尝试将弹出窗口合并到我的项目中。直到我尝试将一个值从javascript传递到php脚本,它才会停止工作。我已经包含了一个指向我使用的示例和原始脚本的链接。对原始脚本做了一些细微的修改。我遇到问题的区域标记为---->

完整脚本可在此处找到:

可在此处找到工作示例:

我在hello.html中有以下内容

<form id='form1' style='width: 1100px'>
    <table>
        <th>Email</th>
        <th>Options</th>
        <tr>
            <td>
                <input type='text' id='email1' size='25' value='bob@mail.com'>
            </td>
            <td><a id='1' href='#null' class='contactus'><img src= 'images/emailbutton.jpg'    title='Email' border='0' height='24' width='24'></img></a>

        </tr>
    </table>
</form>

电子邮件
选择权
下面的js位于我在html中引用的.js中。 因为我有多个表单,所以我使用了以下内容。在我的示例中只显示了一种形式。 下面的警告有效…当我单击html中的图像链接时,显示正确的电子邮件地址

    function findCenter(obj) {
        var deltaX = parseInt(obj.css('padding-left')),
            deltaY = parseInt(obj.css('padding-top'));
        obj.css('left', $(window).width() / 2 - obj.width() / 2 - deltaX + 'px').css('top',  $(window).height() / 2 - obj.height() / 2 - deltaY + 'px');
    }

    $(document).ready(function () {
        $('.contactus').click(function () {
    var element = $(this);
    var J = element.attr('id');
    var email = document.getElementById('email'+J).value;
        alert(email);
        $('#result').html('<h3>Loading</h3>').css('display', 'block');
        findCenter($('#result'));
        $.get('email.php', function (data) {
            $('#result').html(data);
            findCenter($('#result'));
            $('#snd').click(function () {
                var subject = document.getElementById('subject').value;
                var addy = document.getElementById('addy').value;
                var comments = document.getElementById('comments').value;
                     $('#result').append('<br /><br /><div><i>Sending...</i></div>');
                     $.post('lbi_email.php',{mode: 'snd', subject: subject, addy: addy, comments: comments},function(data){
                $('#result').html(data);
                findCenter($('#result'));
    });
    });
    });
    });
    });
功能findCenter(obj){
var deltaX=parseInt(obj.css('padding-left'),
deltaY=parseInt(obj.css('padding-top');
css('left',$(window.width()/2-obj.width()/2-deltaX+'px').css('top',$(window.height()/2-obj.height()/2-deltaY+'px');
}
$(文档).ready(函数(){
$('.contactus')。单击(函数(){
var元素=$(此);
var J=element.attr('id');
var email=document.getElementById('email'+J).value;
警报(电子邮件);
$('#result').html('Loading').css('display','block');
findCenter($(“#结果”);
$.get('email.php',函数(数据){
$('#result').html(数据);
findCenter($(“#结果”);
$('#snd')。单击(函数(){
var subject=document.getElementById('subject')。值;
var addy=document.getElementById('addy').value;
var comments=document.getElementById('comments')。值;
$(“#结果”).append(“

发送…”); $.post('lbi_email.php',{mode:'snd',subject:subject,addy:addy,comments:comments},函数(数据){ $('#result').html(数据); findCenter($(“#结果”); }); }); }); }); });
email.php

javascript没有发送下面的值,输入值=$email没有正确写入(我认为)


在javascript中,您发送的是文字
电子邮件
,而不是
电子邮件
值-

$.post('email.php',{mode: 'snd', email: 'email'},function(data){
将此更改为-

$.post('email.php',{mode: 'snd', email: email},function(data){
在php代码中有一个可变范围问题-
$email
超出了函数的范围

$email=$_POST[ 'email']; 
function showForm(){ 
echo $email;
试着把它放在里面

function showForm(){ 
$email=$_POST[ 'email']; 
echo $email;
最后,在单引号中有
$email
-

echo '<form name="mf" id="mf" action="" method="post">
    <h2>Send Email To Customer</h2><br />
    <input type='text ' value='$email '/> 
    ...
然后在php中将其更改为
$\u GET['email']
-

function showForm(){ 
$email=$_GET[ 'email']; 

伙计,缩进你的代码。这几乎是不可读的。嘿,肖恩…谢谢你的回复。这是我在做了所有建议的修改后发现的…这和我添加评论时不一样:评论。表格冻结。当我现在点击email按钮弹出表单时,来自javascript的电子邮件地址仍然没有显示在php中……我只是看到表单上显示了单词“echo”。谢谢,KurtA quick update…找出回声问题,但是值仍然没有从javascript传递到php。嘿,Sean-电子邮件地址没有显示在showForm的输入框中。我还没有添加代码来实际发送电子邮件。我现在正在做这件事。谢谢,当表单显示时,KurtIt justs的电子邮件地址值似乎丢失了。您可以使用更新的
showForm()
函数编辑您的问题吗。
echo '<form name="mf" id="mf" action="" method="post">
    <h2>Send Email To Customer</h2><br />
    <input type="text" value="'.$email.'"/>
    ...
$('#snd').click(function () {
        $('#result').append('<br /><br /><div><i>Sending...</i></div>');
        var comments = document.getElementById('comments').value;
        $.post('email.php',{mode: 'snd', email: email, comments: comments},function(data){
                $('#result').html(data);
                findCenter($('#result'));
        });
});
$.get('email.php', email: email, function (data) {
function showForm(){ 
$email=$_GET[ 'email'];