我如何使用PHP与JavaScript标签?

时间:2016-10-22 19:42:47

标签: javascript php

我有一张表格。我想在用户点击“保存”按钮时发出警报。然后,如果用户单击是,则应执行一些php代码。那我怎么能这样做呢。我可以在输入标签???

中使用onclick



	<?php	if (isset($_POST['save'])){	?>
<script language="javascript">
    	if (confirm('It should be reloaded, Are you sure you want to save changes?')) {
		<?php $x=$_POST['myName']; ?>
		}
		else{
			<?php $x='nothing' ?>
			}
    </script>
    <?php }
	echo $x;
	?>
<form method="post" action="">
	name:<input type="text" name="myName" />
    city:<input type="text" name="city" />
    email:<input type="email" name="email" />
	<br/>
    <input type="submit" name="save" value="save"/>
</form>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

将您的代码更改为

  <?php 
    // connection 
    if ($_POST['t'] == 'execute'){
       <?php $x=$_POST['myName']; ?>
    }else{
      <?php $x='nothing' ?>
    }
  ?>
<form method="post" action="">
   name:<input type="text" name="myName" />
   city:<input type="text" name="city" />
   email:<input type="email" name="email" />
  <br/>
  <input type="hidden" name="t" value="execute"/>
  <input type="submit" name="save" onclick="return confirm('you message')" value="save"/>
</form>