Change Value of item in a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bmcomp
    New Member
    • Sep 2008
    • 3

    #1

    Change Value of item in a form

    Hi,

    A bit stuck here. I have a form and instead of having labels beside each input box i have the default value set as the label. When the user clicks on it the default value is removed. I do this like so:
    [HTML]<input name="name" type="text" value="Name: " onfocus="if(!th is._haschanged) {this.value=''} ; this._haschange d = true;"/>[/HTML]

    But now when i hit the reset button and the form values are reset but i can't seem to find a way to reset all the _haschanged values back to false.

    This is my reset code:
    Code:
    <a class="link" href="#J1" onclick="
    	var myform=document.getElementById('form')
    		if (myform){
    			var mylist = myform.getElementByTagName('input');
    			if (mylist) {
    				for (var i=0; i<mylist.lenght; i++) {
    					mylist[i]._haschanged=false;
    				}
    			}
    		}
    	myform.reset();
    ">reset</a>
    Any ideas what i'm doing wrong here. Thanks.
    B
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You have a couple of typos:
    getElementsByTagName
    mylist.length

    Comment

    • Rsmastermind
      New Member
      • Sep 2008
      • 93

      #3
      what u r doin that is also fine but go in easier way first.
      Try to write easy codes which you can understand well.

      You can search the tags directly like this.

      var inputelem=docum ent.getElements ByTagName('INPU T');
      var elemLength=inpu telem.length;
      for(i=0;i<elemL ength;i++){


      var elem=inputelem[i];
      elem.value='wha tever You Like';



      }



      In your Case:

      You have written the wrong spelling of '"getElementByT agName"
      It should be"getElementsB yTagName" always use script editor while writing javascript because you will never do a spell mistake.

      ///////Most prominent solution to debug your code
      Always you can check your code by giving alert();
      in the various lines if there is error in the upper line it will not show you alert messg when the code will be executed.

      Comment

      • bmcomp
        New Member
        • Sep 2008
        • 3

        #4
        Thanks guys. Never noticed the spelling!!
        I fixed the spelling sbut it still didn't work so I had a look at the way Rsmastermind suggested to simplify it and it worked.

        Thanks for the help.
        B

        Comment

        Working...