#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Coppell, TX
    Posts
    203
    Rep Power
    0

    Is it possible to use Javascript in a common function include?


    I have a function that is common to several programs. This function simply displays rollover buttons so that choices can be made. I'd like to make this a common function, but since it requires a javascript enabler, I am wondering if thats possible.

    My guess is that i will have to do a "require ("rollover.inc") to include the javascript on each page I use, and then code the button bar as a common PHP function that gets included.

    Is there a better way?

    Kork
    "Any significantly advanced techology is indistiguishable from magic." - Arthur C. Clarke
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    You can include the script directly in the HTML.
    Code:
    <script language="javascript" src="script.js"></script>
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Coppell, TX
    Posts
    203
    Rep Power
    0
    jharnois...thank you verymuch...I'd forgotten that. I dont hardly program in Javascript anymore, and what I did was pretty canned.

    I am still having some problems. I took a standard rollover script that has been a mainstay for me, and put it in a php function. The functions that are common to my application are in an include file called common_fns.php, and I just include that file in each program.

    I already had a standard function called "page_header()" so I put that javascript block in the <head></head> part of that function.

    But, alas, it isnt working, so I'm still trying to debug. Thats why I asked if it even could be done.

    Kork
    "Any significantly advanced techology is indistiguishable from magic." - Arthur C. Clarke
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    Working with JavaScript via PHP can be a pain. Make sure you get all of the quotes escaped properly and if there is any multi-line text, you have to use two backslashes, not one (\\n). I try to stay away from JS as much as possible so I can't offer much more help w/o some code.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Coppell, TX
    Posts
    203
    Rep Power
    0
    He he..ya I gathered!!

    But, your tip, basically solved my problem completely. I just isolated the JS and used your statement (which I've used before but just forgot ... its hell growing old)...and that fixed the problems.

    Thanks!!!

    Kork
    "Any significantly advanced techology is indistiguishable from magic." - Arthur C. Clarke

IMN logo majestic logo threadwatch logo seochat tools logo