SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast Morris Cornet's Avatar
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry JavaScript problem... what the (meuh) am I doing wrong?

    Hey there,

    I'm currently working with a links database script. It uses a html template for every database item. The following code is written for every database record.
    <<source>> and <<header>> are database output fields for every record.
    When I use another page, which just outputs <<header>> and <<source>> for every database record, without the JavaScript, everything works fine.

    Code:
    if (harakiri=="yes"){
    	harakiri="no";
    	knars = "<div align=right>";
    	}
      else{
    	harakiri="yes";
    	knars = "<div align=left>";
    	}
    
    sourcer = "<<source>>";
    if (sourcer != sourcer_old){
    	document.write("</table></div><p>" + knars + "<table width=400><tr><th>" + sourcer + "</th></tr>");
    	sourcer_old = sourcer;
            countsource = 1;}
       else{
       	countsource ++;}
    document.write("<tr><td><<header>></td></tr>");
    As you can see in the code every record is displayed in its own table cell. Once <<source>> changes (the <<source>> field in this database record is different than the <<source>> field in the previous one), the table is closed, and a new table is started, with the current source as <th>.

    Everything worked fine, until I wanted to left-align every first table, put every second table right, and so forth.

    It didn't work. The first table was on the left, but then the second table was on the left too.
    The third, fourth and fifth table were on the right, and another four tables were left-aligned again. This look like random numbers to me.

    There was no link within the database content. The database didn't contain any html or JavaScript, so THAT can't be influental.

    If you have any idea how this is possible.. I would appreciate your reply.


    Thanks in advance,
    Morris Cornet
    Last edited by Morris Cornet; Jul 8, 2002 at 10:41.

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only glanced at the code... this may or may not help. But...

    switch is a reserved word in Javascript. You should use a different variable name instead.

  3. #3
    SitePoint Enthusiast Morris Cornet's Avatar
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down

    Originally posted by randem
    switch is a reserved word in Javascript. You should use a different variable name instead.
    Bummer! Changing name didn't work!!

    Thank you anyway.

  4. #4
    SitePoint Enthusiast Morris Cornet's Avatar
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    changed "switch" to "harakiri"

    You are NOT going to say harakiri is a reserved word in JavaScript!
    Last edited by Morris Cornet; Jul 9, 2002 at 03:02.

  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Where is harakiri set?

    What does the entire loop look like?
    Wayne Luke
    ------------


  6. #6
    SitePoint Enthusiast Morris Cornet's Avatar
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by W. Luke
    Where is harakiri set?

    What does the entire loop look like?
    Oh, I should have told that. "harakiri" is initially set to "no". Then the code snippet from the first post in this thread is generated and executed for every database record. Variables are preserved throughout, so: what value "harakiri" gets depends on the previous database record. If it was "yes", it should get the value "no" for the next record.


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
  •