Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Javascript not working

    hi friends ,


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


    PHP Code:
    <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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This works
    Code:
    <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?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    OR

    Code:
    <input type = submit  name = butt1 value = "Hit" onClick= "disableButton(this);" > 
    
     function disableButton(name)
            {
             name.disabled = true;
            }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks for help A1ien and Aero

    Quote Originally Posted by A1ien51 View Post
    OR

    Code:
    <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
    Last edited by thindrakhya; 12-24-2007 at 01:09 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Script tags buddy

    Code:
    <input type="submit" name="butt1" value="Hit" onclick="disableButton(this);" /> 
    
    <script type="text/javascript">
    function disableButton(el) {
      el.disabled = true;
    }
    </script>
    Trinithis

  • #6
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Trinithis View Post
    Script tags buddy

    Code:
    <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?
    The only way to predict Future is to create it

  • #7
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    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/s...ad.php?t=27736
    That I think would answer your question

    In particular, post #7
    Last edited by Trinithis; 12-24-2007 at 06:43 AM.
    Trinithis

  • #8
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #9
    New Coder thindrakhya's Avatar
    Join Date
    Jun 2007
    Posts
    90
    Thanks
    8
    Thanked 0 Times in 0 Posts
    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?
    The only way to predict Future is to create it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •