10 Replies Latest reply on Apr 8, 2009 12:23 PM by WebKees

    Insert substring in a second hidden field

      Hi,

       

      A small problem here (I think)

      I have created a form with a textarea for a "long description" .

      Also I have a second hidden field in the form (for a short description) in which I want to set the following value:

      "A substring of the of the above textarea field."

       

      How can I do this?

        • 1. Re: Insert substring in a second hidden field
          Albert S. Level 3

          Hi WebKees,

           

          Here is some code I found on the net. Not sure if it will work with a hidden value but its a starting point.

           

          <html>
          <head>
          <title>Textbox Test</title>
          <script type="text/javascript">
          function applyTextboxValues(parentNodeId, txt) {
          var inputs = document.getElementById(parentNodeId).getElementsByTagName("input");
          for(var i = 0; i < inputs.length; ++i) {
          if(inputs[i]["type"] == "text") inputs[i].value = txt;
          }
          }
          </script>
          </head>
          <body id="bodyId">
          Textbox Test<br>
          <br>
          <pre>You can place any number of textboxes in a parent node (used commonly w/ the <body> tag, <span> tag, and <form> tag) with the 'onkeydown' and 'onkeyup' events attached. The tag must have an id, but no matter the number of textboxes, it doesn't take much code. Insert your element's id (in this scenario, 'bodyId' which is the body's id) into the first parameter of applyTextboxValues. Make sure that your body's id doesn't conflict w/ other element's ids. It is also suggested that the textbox's parent node is the <body> tag.</pre>
          <input type="text" onkeydown="applyTextboxValues('bodyId', this.value);" onkeyup="applyTextboxValues('bodyId', this.value);"><br>
          <input type="text" onkeydown="applyTextboxValues('bodyId', this.value);" onkeyup="applyTextboxValues('bodyId', this.value);"><br>
          <input type="text" onkeydown="applyTextboxValues('bodyId', this.value);" onkeyup="applyTextboxValues('bodyId', this.value);"><br>
          <input type="text" onkeydown="applyTextboxValues('bodyId', this.value);" onkeyup="applyTextboxValues('bodyId', this.value);">
          </body>
          </html>

          • 2. Re: Insert substring in a second hidden field
            Günter Schenk Level 4

            Hi WebKees,

             

            you also might want to consider using a PHP function to "echo" a substring of the stored "long description" text -- please see a pointer in this thread on the InterAKT forums.

             

            Cheers,

            Günter

            • 3. Re: Insert substring in a second hidden field
              Albert S. Level 3

              Hi,

               

              Günter's solution is a much better one and you should focus on that first unless your doing something tricky that would require the javascript.

              • 4. Re: Insert substring in a second hidden field
                Level 1

                Hi Günter,

                 

                Thank you for your reply, I read the thread on the InterAkt forum but this is not exactly what I'm looking for.

                I will explain myself better:

                 

                In my database I need 2 fields. The first one with a long description and the second with a short description.

                I need these two field because I want to export them later to xml so I can use it with spry.

                 

                So when the user fills in the insert (or update) form, he only needs to fill in the long description field.

                Now I want the second "hidden" field automatically inserts the first, let's say 30 characters, of what the user just filled in the long description field.

                 

                I hope I made myself clear and that you know a solution for this.

                WebKees.


                • 5. Re: Insert substring in a second hidden field
                  Albert S. Level 3

                  Hi Webkees,

                   

                  The idea is your user enters in the information once "long description" then when you export/create your xml file to only have it pull out 30 or so characters from the "long description". So then later lets say you realize "Hey I want 40 characters!", then you just change the query to only pull out 40 characters. There is alot more control in doing it this way.

                  • 6. Re: Insert substring in a second hidden field
                    Level 1

                    Hi Albert,

                     

                    Yes, that's the idea, but I want in my exported xml file both the long description and the short description.Or is there a way to pull out a certain numbers of characters from the long description in xml?

                     

                    WebKees.

                    • 7. Re: Insert substring in a second hidden field
                      Albert S. Level 3

                      Hi Webkees,

                       

                      Theres always a way . How are you creating your xml file?

                      • 8. Re: Insert substring in a second hidden field
                        Level 1

                        I just create new file "rs2xml_news.php". In this file I create a recordset and than I use the ADDT "Export recordset as xml". Then I upload this file to the server. In another page I create a spry xml dataset and use the "rs2xml_news.php" file as XML source.

                         

                        WebKees.

                        • 9. Re: Insert substring in a second hidden field
                          Albert S. Level 3

                          Hi Webkees,

                           

                          So in your php/xml export file you need to change some thing.

                           

                          1. In your mySql statement to something like:

                           

                          SELECT *, LEFT(LongDescription, 30) as ShortDescription FROM table

                           

                          2. Then add a column to the ADDT code:

                           

                          $xmlExportObj->addColumn("ShortDescription", "ShortDescription");

                           

                          That should do it.

                          • 10. Re: Insert substring in a second hidden field
                            Level 1

                            Wow Albert, it works, you're awesome.

                            This is exactly what I needed.

                             

                            Thank you so much.

                             

                            WebKees.