Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to clear a form on a page refresh or reload without clear button i

tonyv64tonyv64 Posts: 2Member
Being a JavaScript newbie this is bugging me. I have a page with 3 forms. I am currently using in the Body tag: OnLoad="form1.reset(); form2.reset(); form3.reset(); search.reset()"
which clears the form if the user refreshes the page or comes back to it after hitting the back button. It is working fine in IE but not in Netscape 4.7 - 7.0
Any help would be greatly appreciated.

Comments

  • lillulillu Posts: 308Member
    Here's the logic on how to reset a from without making use of the reset function.

    Check each element in the form to see if it is a text field, text area or check box by checking the type property for a text field or checkbox and checking the col property (no. of columns) for textarea. Then set the field's value to null or an empty string ''(for text boxes or text areas) or unchecked (for check boxes).

    After resetting all values it sets the focus to the first field in the form.

    : Being a JavaScript newbie this is bugging me. I have a page with 3 forms. I am currently using in the Body tag: OnLoad="form1.reset(); form2.reset(); form3.reset(); search.reset()"
    : which clears the form if the user refreshes the page or comes back to it after hitting the back button. It is working fine in IE but not in Netscape 4.7 - 7.0
    : Any help would be greatly appreciated.
    :

    [hr][grey]To err is human, but to really foul things up requires a computer. (Farmers Almanac)[/grey] :-)

  • bhekisizwebhekisizwe Posts: 22Member
    : Being a JavaScript newbie this is bugging me. I have a page with 3 forms. I am currently using in the Body tag: OnLoad="form1.reset(); form2.reset(); form3.reset(); search.reset()"
    : which clears the form if the user refreshes the page or comes back to it after hitting the back button. It is working fine in IE but not in Netscape 4.7 - 7.0
    : Any help would be greatly appreciated.
    :
    HI there i agree with lillu u can just set the values of all the input fields to an empty string like ("")e.g

    function go1()
    {
    for(var index=0;index<document.forms[0].length;index++){
    document.forms[0].elements[index].value="";
    }
    }
    the index of the form Arrays should be changed for the other forms like in your case change them to forms[1] and forms[2].And then you can set the onLoad="javascript:go1();go2();go3()"
    Remember repeat the above function but changing the forms array index
    and also change the function name to go2(),go3()respectively so that all the functions are run simultaneously when the page loads.
  • tonyv64tonyv64 Posts: 2Member
    Thanx for replying...
    I'm not sure what you mean by index of Form arrays...

    I actually have 4 forms. The name attributes in the forms are form1, form2, etc.

    I'm not sure what to substitute in the example you provided. Do I rename all of my name attributes to forms[1}, etc.?

    Any extra help would be greatly appreciated.

    Thanx
    Tony


    : : Being a JavaScript newbie this is bugging me. I have a page with 3 forms. I am currently using in the Body tag: OnLoad="form1.reset(); form2.reset(); form3.reset(); search.reset()"
    : : which clears the form if the user refreshes the page or comes back to it after hitting the back button. It is working fine in IE but not in Netscape 4.7 - 7.0
    : : Any help would be greatly appreciated.
    : :
    : HI there i agree with lillu u can just set the values of all the input fields to an empty string like ("")e.g
    :
    : function go1()
    : {
    : for(var index=0;index<document.forms[0].length;index++){
    : document.forms[0].elements[index].value="";
    : }
    : }
    : the index of the form Arrays should be changed for the other forms like in your case change them to forms[1] and forms[2].And then you can set the onLoad="javascript:go1();go2();go3()"
    : Remember repeat the above function but changing the forms array index
    : and also change the function name to go2(),go3()respectively so that all the functions are run simultaneously when the page loads.
    :

  • bhekisizwebhekisizwe Posts: 22Member
    [b][red]This message was edited by bhekisizwe at 2004-3-30 11:51:32[/red][/b][hr]
    : Thanx for replying...
    : I'm not sure what you mean by index of Form arrays...
    :
    : I actually have 4 forms. The name attributes in the forms are form1, form2, etc.
    :
    : I'm not sure what to substitute in the example you provided. Do I rename all of my name attributes to forms[1}, etc.?
    :
    : Any extra help would be greatly appreciated.
    :
    : Thanx
    : Tony

    Hi there tony.Here is a program you can use.

    :
    : function go1()
    : {
    : for(var index=0;index


    Well the thing is i advice you to use forms[0],forms[1],e.t.c
    so that its easy for you to set all values in the forms to an empty string.Just try it goodluck!!!
    :
    : : : Being a JavaScript newbie this is bugging me. I have a page with 3 forms. I am currently using in the Body tag: OnLoad="form1.reset(); form2.reset(); form3.reset(); search.reset()"
    : : : which clears the form if the user refreshes the page or comes back to it after hitting the back button. It is working fine in IE but not in Netscape 4.7 - 7.0
    : : : Any help would be greatly appreciated.
    : : :
    : : HI there i agree with lillu u can just set the values of all the input fields to an empty string like ("")e.g
    : :
    : : function go1()
    : : {
    : : for(var index=0;index<document.forms[0].length;index++){
    : : document.forms[0].elements[index].value="";
    : : }
    : : }
    : : the index of the form Arrays should be changed for the other forms like in your case change them to forms[1] and forms[2].And then you can set the onLoad="javascript:go1();go2();go3()"
    : : Remember repeat the above function but changing the forms array index
    : : and also change the function name to go2(),go3()respectively so that all the functions are run simultaneously when the page loads.
    : :
    :
    :



Sign In or Register to comment.