dongyuxiao6295 2015-03-10 21:01
浏览 160

使用php或javascript清除html表单数据

I've got kind of a situation here : I have the following form :

<form action="sample.php" id="searchform" method="post">
<input type="text" id="key_words" name="key_words" value="<?php echo isset($_POST['key_words']) ? $_POST['key_words'] : '' ?>"style="width:377px;">
<input type="text" name="minimum_price" value="<?php echo isset($_POST['minimum_price']) ? $_POST['minimum_price'] : '' ?>">
<input type="text" name="maximum_price" value="<?php echo isset($_POST['maximum_price']) ? $_POST['maximum_price'] : '' ?>">

I'm using the php script in value because i need to keep the value in text box persistent. So, now i need to clear the values in text box when i click a button:

<button type="reset" value="clear" onclick="clearform()">Clear</button>

I've tried a few things and failed. Help please? JavaScript can also be used for clearform() method.

  • 写回答

2条回答 默认 最新

  • doudui6756 2015-03-10 21:19
    关注

    You just need to get the elements by id and set the value attribute to empty string:

    function clearform()
    {
      document.getElementById('key_words').value = '';
      //same thing for other ids
    }
    

    For your minimum_price and maximum_price you need to add an id since you only have name right now.

    Also in this case since you don't want to use HTML's standard reset functionality don't make the button type reset.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度