Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to pass a string to a function

    Please stop me going mad !
    I have a function that i want to use to alter a window.open command according to which link on the page is clicked.
    in the links i have :
    java script:myfunction()

    and in the header:
    function myfunction()
    stuff
    end function

    i have tried all combinations that i can think of to pass a variable from the link to the function, ie no quotes,double quotes,single quotes etc. in the function i have tried different set ups but to no success, the page either crashes or does nothing at all.
    All examples that i have found seem to pass object values.
    where am i going wrong ?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to pass a string to a function

    fatherjack,

    This works for me. The first one just displays a value passed to it; the second shows the id of the element which raised the event. Is this what you meant?
    <pre><HTML>
    <SCRIPT>
    function showValue(strMessage) {
    alert(strMessage)
    }
    function showEvent() {
    alert (window.event.srcElement.id)
    }
    </SCRIPT>
    <BODY onload=showValue("Loading")>

    <span id="spanid" onclick = "showEvent()">test click</span>
    </BODY>
    </HTML></pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to pass a string to a function

    nice one, not sure what was wrong with my code but this works a treat, thank you

Posting Permissions

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