Results 1 to 5 of 5

Thread: Using variables passed to a function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    28

    Unhappy

    <!--

    Help!! See below. I am trying to pass a variable (option) to a function, which in this case is the id of a paragraph (i.e., "test_paragraph"). I'd like for the function then to turn off the display of the test_paragraph based on the passed variable (option). The id gets passed Ok as witnessed by the alert message. However, it will not work using the option.style.display="none"; whereas it will work if you type the actual name of the paragraph as shown in command that is not commented out (test_paragraph.style.display="none". Is this a syntax problem? Since I'm not a javascript person, a potentially small syntax problem shuts me down. Thanks very much in advance.

    KBH

    -->




    <SCRIPT>
    function turn_paragraph_off(option)
    {
    alert(option)

    test_paragraph.style.display="none";

    // option.style.display="none";

    }
    </SCRIPT>

    <%variable="test_paragraph"%>
    <P onmouseover="turn_paragraph_off('<%=variable%>')" >
    Move the mouse over this sentence make the test paragraph below turn off.
    </p>

    <br>
    <br>
    <br>


    <p id=test_paragraph >
    TEST TEST TEST TEST TEST TEST TEST TEST TEST
    <br>
    TEST TEST TEST TEST TEST TEST TEST TEST TEST
    <br>
    TEST TEST TEST TEST TEST TEST TEST TEST TEST
    <br>
    TEST TEST TEST TEST TEST TEST TEST TEST TEST
    <br>
    TEST TEST TEST TEST TEST TEST TEST TEST TEST
    </p>

  2. #2
    Guest
    Hi, of course you can use a dirty way to do it and just create a small function for every different paragraph. But I guess you don't really wanna do that, huh?

    I have done it before, but since I'm no expert on javascript either, I forgot exactly how. I do remember you have to go through the object model to get to it, so something like:

    window.document.items(option).style.display = "none";

    Of course that's not the right line (I think) but that's the direction you gotta search in..

  3. #3
    Addicted Member
    Join Date
    Jun 2000
    Location
    Pittsburgh, PA
    Posts
    149
    try document.formname.item[option].style.display = "none";
    atleast i think thats it

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Code:
    <HTML>
    <HEAD>
    <SCRIPT language=Javascript> 
    function turn_paragraph_off(option) 
    { 
    alert(option) 
    
    if (document.all[option].style.display=="none")
    	document.all[option].style.display = "";
    else
    	document.all[option].style.display = "none";
    //test_paragraph.style.display="none"; 
    
    // option.style.display="none"; 
    
    } 
    </SCRIPT> 
    </HEAD>
    <BODY>
    <%variable="test_paragraph"%> 
    <P onmouseover="turn_paragraph_off('<%=variable%>')" > 
    Move the mouse over this sentence make the test paragraph below turn off. 
    </p> 
    
    <br> 
    <br> 
    <br> 
    
    
    <p id=test_paragraph > 
    TEST TEST TEST TEST TEST TEST TEST TEST TEST 
    <br> 
    TEST TEST TEST TEST TEST TEST TEST TEST TEST 
    <br> 
    TEST TEST TEST TEST TEST TEST TEST TEST TEST 
    <br> 
    TEST TEST TEST TEST TEST TEST TEST TEST TEST 
    <br> 
    TEST TEST TEST TEST TEST TEST TEST TEST TEST 
    </p>
    </BODY>
    </HTML>
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5
    Addicted Member
    Join Date
    Jun 2000
    Location
    Pittsburgh, PA
    Posts
    149
    guess your not using forms doh. try changing paragraph from id to name. i have had problems with using id in the past, especially in netscape

Posting Permissions

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



Click Here to Expand Forum to Full Width