dtxf759200 2012-12-19 12:21
浏览 43
已采纳

不想刷新和保留最后插入的值

In my htm page i want to use a button which submit my form by using function. I use validations on my fields and when i press submit button it displays error message but doesnot retain last values it refresh my form. I just want that the values that i entered will be exist there and just the field that has only error message will be disappear. all other fields remain there. Here is my code:

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <!--<meta http-equiv="refresh" content="text/html; charset=iso-8859-1" />-->
    <!--
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    -->
    <title>Phone Registration</title>
    <link rel="stylesheet" type="text/css" href="file:///C|/xampp/htdocs/track/css/view.css" media="all"/>
    <script type="text/javascript" src="file:///C|/xampp/htdocs/track/javascript/view.js"></script>
    <script type="text/javascript" src="file:///C|/xampp/htdocs/track/javascript/external.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

    <script>
        $(function() {
            $( "#datepicker" ).datepicker();
        });
        </script>

    </head>
    <body id="main_body" >
        <img id="top" src="file:///C|/xampp/htdocs/track/images/top.png" alt=""/>
            <div id="form_container">
            <h3>
                <a href="file:///C|/xampp/htdocs/track/phonereg.php">Phone Registration</a>
                <a href="file:///C|/xampp/htdocs/track/officerreg.php">Officer Registration</a>
                <a href="file:///C|/xampp/htdocs/track/customerreg.php">Customer Registration</a>
                <a href="file:///C|/xampp/htdocs/track/taskentry.php">Task Entry</a>
            </h3>       
            <form  name="order" id="form_532698" class="appnitro"  method="post" action="" >
                <div class="form_description">
                <h2>Phone Registration</h2>
            </div>                      
            <ul >
              <li>
              <span>
                <label class="description">IMEI # : </label>
                <input name="imei" id="imeinum" class="element text medium" type="text" maxlength="15" value=""/> 

                </span>
              </li>
              <li>
              <span>
                <label class="description" >Phone Number </label>
                <input name="phone" id="phnum" class="element text medium" type="text" maxlength="11" value="" onblur="validate(this)"/>  

                </span>
              </li>
              <li>
              <span>
                <label class="description" >From Date </label>
                <input id="datepicker" name="fdate" class="element text medium" maxlength="10" value="" type="text"/>
                </span>
              </li>
              <li>
              <span>
                <label class="description" for="element_4">Active </label>
                <input name="r1" id="rad" class="element radio" type="radio" value="Yes" checked="checked" />
                <label class="choice">Yes</label>
                <input name="r1" id="rad" class="element radio" type="radio" value="No" />
                <label class="choice">No</label>
                </span>
              </li>

              <li>
              <input type="button" name="save" value="Save" />
              </li>

              <!--
              <li class="buttons">
                    <input type="hidden" name="form_id" value="532698" />
                    <input class="button_text" type="submit" name="save" value="Save" id=""  />
                    &nbsp;<input class="button_text" type="reset" name="cancel" value="Cancel" />
                    &nbsp;<input class="button_text" type="submit" name="search" value="Search" id="" />
                    &nbsp;<input class="button_text" type="submit" name="up" value="Update" id=""  />
                    &nbsp;<input class="button_text" type="submit" name="del" value="Delete" id="" />
              </li>
              -->
            </ul>
            </form>
    </div>
    <img id="bottom" src="file:///C|/xampp/htdocs/track/images/bottom.png" alt=""/>

    <script type="text/javascript" language="JavaScript">
//submit form
document.order.submit();
</script>
    </body>

</html>

Kindly guide me how can i do this?? I'll be thankful to you

  • 写回答

4条回答 默认 最新

  • 普通网友 2012-12-19 12:31
    关注

    You can use this code to prevent form from submiting to server if validation fails:

    $("form").on("submit", function(event){
      if(!isValidForm($(this)){
        event.preventDefault();
      }
    });
    

    supposingly isValidForm() method takes form selector and returns true if form is valid and false if it's not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗