Web Analytics Made Easy -
StatCounter Inserting into a String - CodingForum

Announcement

Collapse
No announcement yet.

Inserting into a String

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inserting into a String

    I have a PHP script that posts a table with submitted info onto page. The problem is that the table widths change depending on how much content the user inputs. I counted the width and figures that by inserting a "\n" every 65 characters would make all tables even. The code I wrote has one error (IE).
    ::Cannot assign to a function result
    ::Line 29
    The function is called in the onblur event in a textarea input
    Code:
    var b;
    var c;
    function fix() {
     var a = bleh.post.value;
     for(b = 0; b <= a.length; b++) {
      if(c = 65) {
       a.charAt(b) = "\n";
       c = 0;
      }
      c++;
    }
    bleh.post.value = a;
    }
    The form is named bleh and the textarea is post.
    In looked at the string.replace() function but that replaces any string in the arguments. I want to INSERT a \n or carriage return every 65 characters.
    --Seph

  • #2
    The content is put inside the textarea field so the table width doesn't change even if the content's length is greater than 65.

    Or do you mean that the content is submitted and displayed in a table in another page? If so, then if you set a fixed width for the table column, the text inside it will automatically wrapped to the next line.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      RE:

      It is submitted and I would not be resorting to JavaScript if the HTML worked. I tried all kinds of CSS and nowrapping in tables. I even set the greater outside table to a smaller length than the inside and it just all expanded. Instead re-writing the whole layout, I just figured I could write some JavaScript to do it for me. Obviosly it is easier said then done but thanks in advance for helping me.
      --Seph

      Comment


      • #4
        Could you show us the table layout?
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Ok this will be pretty long so just bare with me:
          Code:
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <html>
          <head>
          <title>JGGS</title>
          <link rel=stylesheet type="text/css" href="style.css">
          </head>
          
          <body bottommargin="0" leftmargin="50" marginheiht="0" 
          marginwidth="0" rightmargin="0" topmargin="0" 
          background="http://www.presonus.com/content/downloads/wallp
          apers/blue_techno_left.jpg" text="#EE3333">
          <table width="100%" cellpadding="0" cellspacing="0" border="0" height="22">
          <tr valign="top">
          <td width="100" 
          background="images/blue_techno_left.jpg"><img 
          src="images/eatme.jpg" width="21" height="22" border="0"
           alt=""></td>
          <td width="319">&nbsp</td>
          </tr>
          </table>
          <table width="100%" cellpadding="0" cellspacing="0" border="0" height="75">
          <tr valign="top">
          <td width="100%" 
          background="images/blue_techno_left.jpg"><img 
          src="images/BITEME.jpg" width="200" height="50" border="0" 
          alt=""></td>
          <td width="184">&nbsp;</td>
          </tr>
          </table>
          
          <table width="100%" cellpadding="0" cellspacing="0" border="0" height="100%">
          <tr valign="top">
          <Td width="5">&nbsp;</td>
          <td width="160">
          <table width="160" cellpadding="2" cellspacing="="0" 
          border="1" bgcolor="#5200BE" bordercolor="#aa0000">
          <tr valign="top"><td width="160" bordercolor="#7D3C16">
          
          Navigation
          
          </td></tr></table>
          <table width="160" cellpadding="2" cellspacing="0" border="0"
           bgcolor="#A3A3A3"><tr valign="top"><td width="160">
          <a href="?page=Home">Home</a><BR>
          <a href="?page=Games&open=games.php">Games</a><BR>
          <a href="?page=Animation">Animation</a><BR>
          <a href="?page=Tutorials">Tutorials</a><BR>
          <a href="?page=Forum">Forum / Chat</a><BR>
          <a href="?page=Staff Only">Staff Only</a><BR>
          <a href="?page=Members">Members</a><BR>
          <a href="?page=Links">Links</a><BR>
          <a href="?page=About">About</a><BR>
          <font size=1>
          copyright © 1969 <br>guiming justin gray<br>
          <a href="mailto:[email protected]">contact us</a><br>
          <img border="0" 
          alt="Web Counter" 
          src="http://ico.freelogs.com/counter/index.php?u=jggsjggs&s=sbgs" 
          ALIGN="middle" 
          HSPACE="4" 
          VSPACE="2">
          <BR><BR>
          </td>
          </tr></table>				
          <br>
          </td>
          <Td width="10">&nbsp;&nbsp;&nbsp;&nbsp;</td>			
          <td width="70%">
          <table width="70%" cellpadding="0" cellspacing="0" border="0" height="100%">
          <tr valign="top" height="100%">
          <td width="1900">
          <b>
          <hr color="#AABBCC"></b>
          <br>
          <center>
          <table border="1" bordercolorlight="#000000"  
          bordercolor="#000000" bordercolordark="#666666" 
          cellpadding="0" cellspacing="0" width="350">
          <tr>
          <td>
          <table border="0" cellpadding="0" cellspacing="0"  width="350"
           height="23" background="images/jl.jpeg">
          <tr>
          <td>
          </td>
          </tr>
          </td>
          </tr>
          </table>
          <!-- table starts here -->
          <table border="1" bordercolorlight="#666666" 
          bordercolordark="#ffffff" background="images/background.jpg" 
          cellpadding="0" cellspacing="0" width="350" height="15">
          <tr>
          <td width="44"><font color="#1111AA">
          <b>Name</b>:</font>
          </td>
          <td width="306"><font color="#AA1111">
          Test</font>
          </td>
          </tr>
          <tr>
          <td width="44"><font color="#1111AA">
          <b>Date</b>:</font>
          </tD>
          <td width="306"><font color="#AA1111">
          March 10, 2004, 3:51 pm</font>
          </tD>
          </tr>
          <tr>
          <td width="44"><font color="#1111AA">
          <b>Title</b>:</font>
          </tD>
          <td width="306"><font color="#AA1111">
          Bleh</font>
          </tD>
          </tr>
          <td rowspan="2" colspan="2" align="left" valign="top"><font color="#AA1111">
          This is the table that the stuff is submitted into. 
          abcdefghijklmnopqrstuvwxyz12345678910111213141516171819
          2021222324252627282930
          
          </font>
          </td>
          </tr>
          </table>
          </table>
          </center>
          <!-- ends here -->
          
          
          </td>
          <td width="20">
          &nbsp;
          </td>
          <td align="left" valign="top" height="100%">
          <table border="1"  height="60%" bgcolor="A3A3A3" cellpadding="0" cellspacing="0">
          <tr>
          <td>
          &nbsp;
          </td>
          </tr>
          </table>
          </td>
          </tr>
          </table>
          </td>
          
          </tr>
          </table>
          
          
          </body>
          </html>
          There is the whole source for the page it is submitted to.
          --Seph

          Comment


          • #6
            You put long dummy data without spaces in it, that's why the width of the table adjusted and the long text didn't wrap.

            If you really wanted to have a fixed table width, you can put the text inside a div with width equal to the column width and overflow set to auto so that scrollbars will display as needed.

            <td rowspan="2" colspan="2" align="left" valign="top">
            <div style="width:350px;height:150px;overflow:auto">
            This is the table that the stuff is submitted into.
            abcdefghijklmnopqrstuvwxyz123456789101112131415161
            71819
            2021222324252627282930
            </div>
            </td>
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              Thank you for your help. I am not very experienced with CSS so I did not realize that it offered a nowarp inside DIV. But just for future reference, is it possible to insert into a string?
              --Seph

              Comment


              • #8
                Yes, of course it's possible to insert newline into a string.
                But not advisable to do in this case. You wouldn't know that the 65th character is within a word which wouldn't make sense because the word would be broken into two.
                i. e.
                Code:
                The quick brown fox jumps over the lazy dog near the bank [color=red]o[/color]
                [color=red]f[/color] the river.
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  That's exactly what I want

                  Hi Guys,

                  But that is exactly what I was looking for. I have a DB column that takes exactly 45 characters wide and 4 lines max. So, I want to count the characters as it is being type and add a \n at every 46th character. Yes, even if it cut the words in two. How do I do this? I am very new to javascript. Any help would be appreciated . Thank you.

                  -DRM

                  Comment

                  Working...
                  X