Search code examples
phpformsfieldreset

Ignore Resetting A Field When Checkbox Checked in PHP Form


I am trying to write code in PHP where if a certain field is checked...

<input type="checkbox" name="OmitDate" value="true" value="<?php echo htmlspecialchars($OmitDate);?>">

...When the Clear button is selected...

<input type="reset" value="Clear">

...It doesn't clear certain fields in the form

<input type="text" name="Date" size="140" value="<?php echo htmlspecialchars(urldecode($Date));?>">

It this possible?


Solution

  • PHP is not for client side operations. Use Javascript.

    i.e. with jQuery you would do something like:

    $('#buttonID').click(function(){
        $('#textFieldID').val('');
    });
    

    simple inline javascript can be:

    <button id="clearButton" onclick="document.getElementById('textFieldId').value='';">Clear</button>