提交表单后在页面上显示消息

时间:2018-05-01 17:06:11

标签: javascript

我有一个包含2个字段的表单(对于此示例),我使用JavaScript验证,如果字段包含数据,则表单将在用户单击“提交”按钮时提交。我在表单标签中使用iframe将输出发送到同一页面。

我想要做的是在表单下方显示一条消息,说明"感谢您的提交和#34;。我很难想出这个部分。



function SubmitRentalForm()
{
	var bValid    = true;
	var sFirst     = document.getElementById("fname").value;
	var sLast     = document.getElementById("lname").value;
	
	if  ( (sFirst.trim() == "")   || (sLast.trim() == "") )
	{
	        bValid = false;
	        return bValid;
	}

	return bValid;
}

  <div class="main">
      <form name="RentalForm" action="email-rental.php" method="POST" onsubmit="return SubmitRentalForm()" target="myFrame">

      <table id="form_corners_rental" border="0" cellspacing="5">
      <tr>
	<td>First Name</td>
	<td><input type="text" id="fname" name="fname" size="50" maxlength="60" placeholder="Enter First Name"  onblur="ValidateField(name)" />
	<span id="errorname" style="font-size:9px;color:darkred;"></span>
	</td>

	<td>Last Name</td>
	<td><input type="text" id="lname" name="lname" size="50" maxlength="60"  placeholder="Enter Last Name"  onblur="ValidateField(name)"  /></td>
       </tr></table>

     <div id="Msg" style="display:none">
      Thank you for your form submission.
      </div> 

     <br/><br/>
     <input id="submit-btn-rental"  type="submit" value="Rent Now">
      </form>
</div>

<iframe name="myFrame" width="1" height="1" style="border:none"></iframe>
&#13;
&#13;
&#13;

我添加了div标签,但我不知道该怎么做。

有人可以指出我正确的方向。

2 个答案:

答案 0 :(得分:3)

只需在提交表单时更改msg div的样式

&#13;
&#13;
function SubmitRentalForm()
{
  var msg =document.getElementById("Msg")
	var bValid    = true;
	var sFirst     = document.getElementById("fname").value;
	var sLast     = document.getElementById("lname").value;
	
	if  ( (sFirst.trim() == "")   || (sLast.trim() == "") )
	{
	        bValid = false;
	        return bValid;
	}
   msg.style.display="inline-block"
	return bValid;
 
}
&#13;
<div class="main">
      <form name="RentalForm" action="email-rental.php" method="POST" onsubmit="return SubmitRentalForm()" target="myFrame">

      <table id="form_corners_rental" border="0" cellspacing="5">
      <tr>
	<td>First Name</td>
	<td><input type="text" id="fname" name="fname" size="50" maxlength="60" placeholder="Enter First Name"  />
	<span id="errorname" style="font-size:9px;color:darkred;"></span>
	</td>

	<td>Last Name</td>
	<td><input type="text" id="lname" name="lname" size="50" maxlength="60"  placeholder="Enter Last Name"  /></td>
       </tr></table>

     <div id="Msg" style="display:none">
      Thank you for your form submission.
      </div> 

     <br/><br/>
     <input id="submit-btn-rental"  type="submit" value="Rent Now">
      </form>
</div>

<iframe name="myFrame" width="1" height="1" style="border:none"></iframe>
&#13;
&#13;
&#13;

答案 1 :(得分:3)

试试这个

GROUP BY
$query->whereHas('customers', function($query) {
    $query->where(...)
})