#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    21
    Rep Power
    0

    Reset/clear out the default values


    Hi,

    I have the form with with default value for fname and lname. I want to reset/clear out the default values. The code below seems to work but it also clears out the buttons as well.
    When I click on the Reset button, It clears out the name from the Submit and Reset button. How can I clear out only for fname and lname but not for the buttons?

    <script type="text/javascript">
    //reset form
    function reallyreset(){
    var f= document.getElementsByName("myform")[0]; //or whichever form;
    var A= f.elements?f.elements:f.getElementsByTagName("*"), L=A.length,tem;
    while((L--)>=0){
    tem= A[L];
    if(tem.defaultValue)tem.defaultValue= '';
    }
    }
    </script>

    <cfform name="myform" action="" method="post" id="myform">
    First Name<cfinput type="text" name="fname" value="#variables.fname#" size="35" /></th>
    Last Name<cfinput type="text" name="lname" value="#variables.lname#" size="35" />

    <cfinput type="submit" id="submit "name="submit" value="Submit" class="button"></td>
    <cfinput name="resetBtn" id="resetBtn" type="button" value="Reset" onclick="reallyreset()"><
    </cfform>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    26
    Rep Power
    0
    //reset lname and fname
    function reallyreset(){
    document.myform.fname.value="";
    document.myform.lname.value="";
    }

IMN logo majestic logo threadwatch logo seochat tools logo