SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to make use of dynamically generated content in Javascript?

    Hello, my question is how to incorporate html placeholders e.g. { page_link } into Javascript? I have used {page_link} in my html to pick up fixed parameters from MySQL, and now I need to utilize the same placeholder in Javascript to pick up the same parameters. Does anyone know how to do that?

    Thank you!
    Last edited by pedalcars; Apr 29, 2008 at 21:26.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    A more appropriate method may be to use identifiers.

    Code javascript:
    <p id="page_link"></p>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, the html code is like:
    Code:
    <img src="images/{listing_photo1}">
    The javascript code is like:
    Code:
    <script language="javascript" type="text/javascript">
    addPhoto('photo1','photo1 caption','thumb_photo1');
    </script>
    I need to achieve something like:
    Code:
    <script language="javascript" type="text/javascript">
    addPhoto('{listing_photo1}','image caption here','thumb_{listing_photo1}');
    </script>
    Obviously it's not working, so do you have any idea how that can be achieved?

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using php to populate your html with the values? Why wouldn't it also work on the javascript?

    example:
    Code:
    <html>
    <body>
    <img src="images/{listing_photo1}">
    <script type="text/javascript">
    addPhoto('{listing_photo1}','image caption here','thumb_{listing_photo1}');
    </script>
    </body>
    If I have a php function to replace all {listing_photo1} with eg images/house.jpg, it will do it throughout the file not just in the html part.

    If your html and javascript are in different files, you will need to use php to process the js file too.


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
  •