SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot GregShasta's Avatar
    Join Date
    Jul 2001
    Location
    atlanta ga
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing arguments to a function

    ive been fooling with this for a little while now. how do you pass an argument to a function.

    this is the function in the head:
    <script language="javascript">
    function jinky(){
    some.style.display='inline'}
    </script>

    this is the call:
    <div onClick="jinky()"></div>

    now this makes the div 'some' which did have a display of 'none' now become visible. which is fine. however i have several i want to do this with. why doesnt this function work:
    <script language="javascript">
    function jinky(txt){
    txt.style.display='inline'}
    </script>

    this is the call:
    <div onClick="jinky('some')"></div>

    when i use this i get an error message. in short i guess in short how do you pass an argument to a function.

    thx,
    Greg


    ------------------
    'yall sell biscuits in here'--slingblade

  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to tell the function what to expect. For example, if you want to use a function that opens a popup window. You want to be able to define the window size and URL string each time you call the function so you do this:

    function OpenWindow(width,height,URL)

    Then, when you call the function, you would do this:

    javascript: OpenWindow('100','100','somepage.html')

    That's the way it works. The best way to learn is to look at someone elses function and figure it out.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Greg,

    I think you'd probably be better off reading this DHTML tutorial. This way, your code will be cross-browser. Here's the link:

    http://www.pageresource.com/dhtml/ryan/

    However, what you can use that should work is:

    <script language="javascript">
    function jinky(txt){
    txt.style.display='inline'}
    </script>

    this is the call:
    <div onClick="jinky(some)"></div>

    aDog

  4. #4
    SitePoint Zealot GregShasta's Avatar
    Join Date
    Jul 2001
    Location
    atlanta ga
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    adog thanx man it works now. ill cross browser it later.

    oscar de la renta,
    Greg

    =================
    'yall sell biscuits in here'--slingblade


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
  •