...

View Full Version : Javascript not working



thindrakhya
12-21-2007, 03:34 AM
hi friends ,


I am just greying the submit button by press it and i am not able to do that



<input type = submit name = butt1 value = "Hit" onClick= "disableButton(this.name);" >

function disableButton(name)
{
name.disabled = true;


}

Can anyone tells me where is th error

_Aerospace_Eng_
12-21-2007, 05:24 AM
This works

<input type="submit" onclick="this.disabled = true;" value="Hit">
but after hitting submit the page reloads because the form submits so the button isn't disabled anymore. You need to set some type of session or cookie that detects to see if the form has been submitted already or not though of course the user can just disable js. What exactly are you trying to do anyways?

A1ien51
12-21-2007, 10:30 PM
OR



<input type = submit name = butt1 value = "Hit" onClick= "disableButton(this);" >

function disableButton(name)
{
name.disabled = true;
}


Eric

thindrakhya
12-24-2007, 12:07 AM
Thanks for help A1ien and Aero


OR



<input type = submit name = butt1 value = "Hit" onClick= "disableButton(this);" >

function disableButton(name)
{
name.disabled = true;
}


Eric



A1ien i wanted to know what was wrong with this.name

Does it mean that i was giving the name of element and by using this you are providing the reference of that element

I tried document.form[0].name.disabled = false

It also did not work ,

I wanted to know the mechanism behind this

Thank you

Trinithis
12-24-2007, 01:23 AM
Script tags buddy



<input type="submit" name="butt1" value="Hit" onclick="disableButton(this);" />

<script type="text/javascript">
function disableButton(el) {
el.disabled = true;
}
</script>

thindrakhya
12-24-2007, 03:02 AM
Script tags buddy



<input type="submit" name="butt1" value="Hit" onclick="disableButton(this);" />

<script type="text/javascript">
function disableButton(el) {
el.disabled = true;
}
</script>



I know that i had to put script tags what i was asking is that


disableButton(this) is working but
disableButton(this.name) was not working
Why?

Trinithis
12-24-2007, 05:33 AM
In all, you are acting upon the html element, not it's name. I'm not sure how much OOP you know, but if you understand it well, thinking in OO terms should make this rather apparent.

Another way of thinking about it is: Are you disabling the element's name, or are you disabling the element? (You are disabling the element.)

There's a similar thread here:
http://www.dynamicdrive.com/forums/showthread.php?t=27736
That I think would answer your question

In particular, post #7

A1ien51
12-24-2007, 02:09 PM
Lets say you are at a party. You have a name tag. You hand that name tag to a friend and they go into a room and introduce you to your friends. Instead of introducing you, they introduce your name tag since that is all the information they have. So that is "this.name".

Now lets say they have a board full photos listed by the name. Your friend walks in and says here is "foo". They can look up on th board and say document.formName[name] is the photo of foo. So if you only give the name, you would need to use the form array to look up the element.

Finally instead of giving your friend your name tag, you walk in with them. [this]. People know who you are since you are there. That is what happens when you pass in the reference to the object. You have a reference to the real thing and no reason that someone has to do a lookup on that "photo wall".

Hopefully that helps clear up why this.name and this works in that manner and how to make this.name work. It is better to pass in an object when you can since that is one less lookup that the code has to do to get information that you already had to begin with.

Eric

thindrakhya
12-27-2007, 02:04 AM
Thanks A1ien for the explanation

Just wanted to know one final thing
Are these two statements are same


1) document.form[0].name.disabled = false
2) document.form[0].element[0].disabled = false

DO they both work or 1 will work
or first one is totally wrong and not exists

and there is no way to update any element property if we know its name

Is there any function which can return the reference of the object if we know its name or have to build function by using for loop and go through all elements?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum