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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing form element properties using onchange?

    Hello,

    I have 1 form, and dozens of elements. In the select elements I use onchange="somefunc()". In this function I'd like to access and change the form element attributes (such as form.element.option[].value and form.element.option[].innerHTML).

    Is there a way to access the element that has just changed (unsing onchange="somefunc()") by passing a "this.element" parameter to access the elements properties such as form.element.option[].value within the function?

    Thanks

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    you can pass "this" and that will give you a reference to the select field.
    Code:
    onchange="someFunc(this);"
    Or you can use:
    Code:
    // ** code blatantly copied and pasted from www.quirksmode.org
    	var targ;
    	if (!e) var e = window.event;
    	if (e.target) targ = e.target;
    	else if (e.srcElement) targ = e.srcElement;
    	if (targ.nodeType == 3) // defeat Safari bug
    		targ = targ.parentNode;
    putting this at the very beginning of your event handler will result in the variable targ pointing to the element that fired/dispatched the event.

    Hope that helps.

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it sure does help! thanks a bunch man


  •  

    Posting Permissions

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