www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need help with changing a button's onclick

  1. #1
    Join Date
    Nov 2009
    Posts
    13

    Need help with changing a button's onclick

    I'm baffled as to why I'm getting a "null" when trying to assign a new onclick to a form button after it's clicked. When I troubleshoot I'm using alerts. Here is my code:

    Code:
    alert(document.getElementById(formName).onclick);
    // this first alert yeilds: function onclick(event) { javascript:readTextFile("81","plus"); }
    			   document.getElementById(formName).onclick = 'javascript:readTextFile("81","minus")';
    			   alert(document.getElementById(formName).onclick);
    // this second alert yields: null
    Am I assigning the onclick incorrectly?

  2. #2
    Join Date
    Nov 2009
    Posts
    13
    I tried adding ".value" after "onclick" but that didn't work either. It does not change it at all when I do that. I get the same as the first alert. Why won't it change the onclick???
    Last edited by Pat the Rat; 07-08-2014 at 08:24 AM.

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,133
    if you use DOM correctly then your referencing will be...

    document.formName.formElementName.property

    so adding a new onclick would be something like

    document.formName.formElementName.onclick = function(){ /* stuff in here */}

    in one of my scripts I have a loop that grabs the particular element called doc, it then applies an onclick event to it like so...
    Code:
    doc.onclick = function(){ report("Mouse Click in cell : " + this.innerHTML);} // this will be replaced with something useful
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Nov 2009
    Posts
    13
    that seems to work. thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles