简体   繁体   中英

Use link click to clear input field Javascript

I am trying to use a link to clear a text input field. I am hiding and showing a memo field and and if the user puts text in the field and clicks "remove memo" link I want to text field to clear on click.

    <html>
    <head>
    <script language="JavaScript">
function toggle(id) {
    var state = document.getElementById(id).style.display;
        if (state == 'block') {
            document.getElementById(id).style.display = 'none';
        } else {
            document.getElementById(id).style.display = 'block';
        }
    }

    oldTextAry = new Array();

    function changeText (fieldObj, newTexStr) {
    if (newTexStr == fieldObj.innerHTML) {
    fieldObj.innerHTML = oldTextAry[fieldObj.id];
    } else {
    oldTextAry[fieldObj.id] = fieldObj.innerHTML;
    fieldObj.innerHTML = newTexStr;
    }
    }

    </script>
    <style type="text/css">
    <!--
    #hidden1 {display: none;}
    -->
    </style>
    </head>
    <body>


    <a href="###" onclick="toggle('hidden1'); changeText(this,'Remove Memo');" class="memo" >Add Memo</a>
    </div>

    <div id="hidden1"><div class="memo">Memo: <input type="text" id="ctlWorkflow_ctlMemo381" size="45" maxlength="32" name="ctlWorkflow:ctlMemo381"></div>        </div>                     

    </body>
    </html>

I am stuck and cannot get the field to clear.

Use the below code in the click delegate. Sorry for the mistaken answer.

document.getElementById("ctlWorkflow_ctlMemo381").value = '';

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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