SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getelementbyId ??

    Hey,

    I am a complete coding n00b and i'm trying to get the following done:
    basically i'm generating a table with book related fields such as author, title etc, and the last column is supposed to have a link to the pdf. To save some work i thought on generating a dynamic 'id' for each <tr>. Then i just have to rename all the docs to "document(id number).pdf"

    The problem is that i dunno where to begin, i've been reading on the getElementById () but no success yet.

    Stupid Example of what i want:
    Code:
    ....
    <tr id='122'>
    <td><a href='document".$id.".pdf'>view pdf </a></td>
    ...
    </tr>
    ...
    
    Any help will be greatly appreciated.
    Regards,

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This best done with server side script, php, perl etc, your example has $id, looks like PHP variable to me.

    You define the dataset then have php loop through it and produce the HTML output for you, you also can name your pdf anything, so as to be more descriptive for people who see the file later on their desktops for example.

    Back to getElementById(), it simply returns a HTML element with that specific Id, you are going the wrong way with this I'm thinking.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you modify in your back-end? instead of using javascript. I only use javascript when I need to do some interactive effect i.e. hide and show.

    Usually I use javascript prototype framework to make my life easier when it come to query an object. You can use $('id'), or a collection

    $A(document.getElementsByTagName('TR')).each(function (){doSomething();});

    and one thing, I am not sure that getElementById is supported by all browsers.

  4. #4
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx for the answers guys!
    I decided to give up on javascript, too late to learn it anyways. (have to get this working by tomorrow).

    The thing was that i received a dvd with all the pdf plus an excel file with all the info, and the table is supposed to be to a multimedia cd, that's why i tought in js. I am currently converting the excel data to mysql tables, then i'll simply generate a table with some loops and copy paste it to a plain html file.

    Thanks both for pointing me into the right direction
    _o_

  5. #5
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tolio View Post
    I decided to give up on javascript, too late to learn it anyways. (have to get this working by tomorrow).
    Ahhhh, don't we just love people that think that the JavaScript is the most trivial part in a project and that it can be solved only one day before a release.



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
  •