繁体   English   中英

使用javascript重置表单字段(除了一个字段)

[英]Reset form fields except one using javascript

我有一个试图合并一个重置按钮的表单。 我有一个只读文本字段,我要在当天进行提取。 我的目标是合并重置以清除所有字段,但保留日期字段不变。 我似乎不知道该怎么做。 我目前拥有的功能将清除所有内容。

这是我所拥有的功能:

function confirm_ShortageReset()
{

        var datesValue = document.getElementById('dates').value;
    alert(datesValue);
    //return confirm("Are you sure?");  
    document.getElementById('shortage').reset();
document.getElementById('dates').value = datesValue;
}

我正在考虑将日期值复制到另一个变量中,一旦清除生效,便可以通过调用保存日期的变量来重新输入日期。 这可能吗?

这也是我的形式。

<form action = "drivers.php" target = "drivers.php" method = "post" name = "shortage" id = "shortage" onsubmit = "return validateShortage()">
<table id = "main">
<tr>
    <td><table id = "shortages">
    <h1> Shortages </h1>
    <thead>
    <tr>
        <th> Date </th> 
        <th> Driver </th>
        <th> Customer# </th>
        <th> Invoice# </th>
        <th> Product Description </th>
        <th> Size </th>
        <th> Cases </th>
        <th> Bottles </th>
        <th> On Truck </th>
        <th> CHK Itls </th>
        <th> Notes </th>
    </tr>
    </thead>

    <tr>
        <td> <input type = "text" id = "dates" size = "6" name = "dates" readonly = readonly onblur = "checkDate()" > </input></td>
        <td>
        <select id = "drivers" name = 'drivers' >
            <option value = ""> </option>
            <option value = "driver1"> driver 1 </option>
        </select></td>

        <td> <input type = "number" min = "1" max = "99999999" id = "customernum" name = "customernum" > </input> </td>
        <td> <input type = "number" min = "1" max = "99999999" id = "invoicenum" name = "invoicenum" > </input> </td>
        <td> <input type = "text" id = "proddes" name = "proddes" > </input> </td>
        <td> <input type = "text" id = "size" name = "size" > </input> </td>
        <td> <input type = "number" min = "0" max = "999999" id = "cs" name = "cs" > </input> </td>
        <td> <input type = "number" min = "0" max = "999999" id = "btls" name = "btls" > </input> </td>
        <td> <select id="ontruck" name = "ontruck">
            <option value = " "> </option>
            <option value = "Y"> Y </option>
            <option value = "N"> N </option>
        </select> </td>
        <td> <select id = "chkitls" name = "chkitls" > 
                <option value = " "> </option>
                <option value = "check1"> check1 </option>

            </select> </td>
        <td> <input type = "text" Id = "notes" name = "notes"> </input> </td>   


    </tr>


    </table>

    <tr>
        <td><input type = "submit" value = "Submit" name = "mydrivers" > </td>
        <td><input type = "reset" value = "Clear All" onclick = "return confirm_ShortageReset();"> </input></td>

    </tr>

    <tr ><td></td><tr /><tr ><td></td><tr /><tr ><td></td><tr />
    <td> <hr /> </td>
</table>
</form>

请检查此代码

<script type="text/javascript">
 function confirm_ShortageReset(){
 var datesValue = document.getElementById('dates').value;
  document.getElementById('shortage').reset();
 document.getElementById("dates").setAttribute('value',datesValue);
  }
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM