By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Change Value of item in a form

P: 3
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(!this._haschanged){this.value=''}; this._haschanged = 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:
Expand|Select|Wrap|Line Numbers
  1. <a class="link" href="#J1" onclick="
  2.     var myform=document.getElementById('form')
  3.         if (myform){
  4.             var mylist = myform.getElementByTagName('input');
  5.             if (mylist) {
  6.                 for (var i=0; i<mylist.lenght; i++) {
  7.                     mylist[i]._haschanged=false;
  8.                 }
  9.             }
  10.         }
  11.     myform.reset();
  12. ">reset</a>
Any ideas what i'm doing wrong here. Thanks.
B
Sep 18 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
You have a couple of typos:
getElementsByTagName
mylist.length
Sep 18 '08 #2

P: 93
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=document.getElementsByTagName('INPUT');
var elemLength=inputelem.length;
for(i=0;i<elemLength;i++){


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



}



In your Case:

You have written the wrong spelling of '"getElementByTagName"
It should be"getElementsByTagName" 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.
Sep 19 '08 #3

P: 3
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
Sep 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.