HTML JavaScript:使用弹出窗口?

时间:2013-12-25 08:59:24

标签: javascript html

我尝试创建一个用于更改密码的弹出窗口。

以下是我的尝试:

<form name="passwd" action="passwd.php" method="POST" >
Old Password:<input type="text" id="oldpwd" name="old_password" ><br>
New Password:<input type="text" id="newpwd" name="new_password" ><br>
Confirm Password:<input type="text" id="conpwd" name="confirm_password" ><br>
<input type="submit" value="Change password" width="5" id="cp">
</form>

2 个答案:

答案 0 :(得分:0)

我的方式是这样的:

template.html:

<div class="errormsg">#ERROR#</div>

的script.php:

<?php 
     $template = file_get_contents('template.html');
     if ($template !== NULL) {
         $error = array();
         if ($_POST['email'] == '') {
             $error[] = "The field email is empty";
         }

         $errorStr = '';
         foreach ($error as $message) {
             $errorStr .='<p>'.$message.'</p>';
         }

         $template = str_replace('#ERROR#',$errorStr,$template);
     }   

如果您想使用jquery而不是查看event.preventDefault

答案 1 :(得分:0)

     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script>
    function Ajax(Form)
    {
     $.ajax({
       cache: false,
            type: 'post', 
            url: 'ChangePasswordPhpScript.php',
            data: $(Form).serialize(), 
            success: function(result) {  
           $('#info').html(result);
     }});
    return false;
    }
    </script>
<form onsubmit="return Ajax(this)">
<div id="info"></div>
<input type="text" name="email"><br/>
<input type="text" name="old"><br/>
<input type="text" name="new"><br/>
<input type="text" name="confirm"><br/>
<input type="submit" name="update" value="update"><br/>
</form>