在两个javascript函数之间传递表单POST参数

时间:2018-01-29 17:28:45

标签: javascript

这是我的HTML代码:

<form name="frmMain" action ="<?php echo(htmlentities($_SERVER['PHP_SELF'])); ?>"
 method="post" onsubmit="return validateform(this);" enctype="multipart/form-data">
 ...
 ...
  ...
<button type="submit" name="btnSubmit" class="btn btn-default" 
    style="position: relative; float:right; margin-right: 50px;">Submit Evaluation 
    <i class="glyphicon glyphicon-chevron-right"></i></button>
</form>

单击提交评估按钮时,javascript中的此功能会触发:

function validateform(frm)
{
    var html=""; // to store the html content

    // Build the content of the create vendor popup form
    html+="<div class='col-md-12 divPreview' id='divPreview'>\n\
<div class='col-md-12 divBackground' id='divBackground'>\n\
<button type='submit' name='btnSubmit' class='btn btn-default' onclick='return SubmitForm(frm);'>Submit</button>\n\
</div></div>";

    $("#divPreview").html(html); // display processing popup form
    return(false);
}

它实际上是一个预览div,其中包含一个提交以下方法的按钮:

function SubmitForm(frm)
{
    .. do some processing here
    frm.submit(); // submit the form
    return(false); // to prevent the calling form from executing
}

如何将frm form参数从validateform()传递给submitform()?

我这样做了,现在它正在运作:

function validateform(frm)
{
    var html=""; // to store the html content

    // Build the content of the create vendor popup form
    html+="<div class='col-md-12 divPreview' id='divPreview'>\n\
<div class='col-md-12 divBackground' id='divBackground'>\n\
<button type='submit' name='btnSubmit' class='btn btn-default'>Submit</button></div></div>";

    $("#divPreview").html(html); // display processing popup form
$("#btnSubmit").on("click", function(){ SubmitForm(frm); });
    return(false);
}

0 个答案:

没有答案