SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing function parmeter

    Hi,
    I have this really simple function and for the life of me i cant remember how to pass the fieldname which is passed in the function.

    Code JavaScript:
    function Change(fieldName)
    	{
    		if(document.mainDetails.enable.checked == true) 
      			{ 
    				document.mainDetails.fieldName.disabled = false; 
    			}
    		else
      			{
    				document.mainDetails.fieldName.disabled = true;
    			}
    	}

    put me out of my misery please.

    Thanks
    CHris

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    Change("my_field_name");

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    Code:
    Change("my_field_name");
    thanks for replying.

    i am already passing the field name ok as if I do
    alert(fieldName); I can see it. but how do I pass that to the
    document.mainDetails.fieldName.disabled = false; line as that brings an error saying it cant find an element called fieldName

    Thanks
    CHris

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Code Javascript:
    document.mainDetails[fieldName].disabled = false;

  5. #5
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, I was using curly brackets instead of square brackets


Bookmarks

Posting Permissions

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