write a variable to a html page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jpollack
    New Member
    • Mar 2008
    • 6

    write a variable to a html page

    I don't know JavaScript but have been tasked to write a script that will change the value of a Boolean variable to the word "Yes" on a table row. I have been trying to achieve this based on my knowledge of ActionScript. Needless to say, I have not been successful!

    ##CUSTOM_SUB_MA RKETEYE## is a tag that pulls the Boolean result from a database. It returns 1 when it is true and null when it is false. I need to convert that "1" to the word "Yes" and write the word "Yes" to a row in my table.

    I realize how much I am asking but would be eternally grateful if someone would help me with this. I appologize, I just don't know where to start. I have been searching the web and begging favors for a day and a half and have gotten absolutely no where. Thanks in advance to anyone who will help! Julie


    Code:
    <script type="text/javascript"><!--
    document.getElementById("##CUSTOM_SUB_MARKETEYE##");
    var Marketeye = "##CUSTOM_SUB_MARKETEYE##";
    if (Marketeye == true) 
    {
    Marketeye = "Yes";
    }
    else
    {
    Marketeye = "No";
    }
    // --></script>
    This is my html document. Where the ##CUSTOM_SUB... ## tags are in my html is where I need to write the converted variable. I do not have to have the tags there.

    [HTML]<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>
    </head>
    <body
    <p>&nbsp;</p>

    <div class="mainDiv" align="center">
    <img src="http://www.mycmdirect. com/webimages/directweb/7/email_header.jp g" alt="TTI - Never Short on Solutions" title="TTI, Inc. - Never Short on Solutions" height="144" width="669" />
    <table style="height: 392px;" align="center" border="0" cellpadding="1" cellspacing="2" width="669">
    <tbody><tr>
    <td colspan="2" class="promoLin e" height="29" width="706">Feb ruary 28, 2008 </td>
    </tr>
    <tr>
    <td align="left" valign="top"><p >&nbsp;</p>
    <p>Thank you, ##FIRSTNAME##,< b> </b>for your interest in TTI's free eNewsletter service. Our records indicate you subscribed to the following electronic newsletters and/or emails:</p>
    <table style="height: 148px;" border="0" width="667">
    <tbody><tr>
    <td width="177"><b> MarketEye</b></td>
    <td bordercolor="#F FFFFF" width="480">&nb sp;<b>##CUSTOM_ SUB_MARKETEYE## </b>&lt;%= Marketeyeyn%&gt ;<b> </b><span style="color: navy; font-family: Arial; font-size: x-small;"><span style="font-size: 10pt; color: navy; font-family: Arial;"></span></span></td>
    </tr>
    <tr>
    <td><b><i>IP&am p;E Matters</i></b></td>
    <td bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_I PE_MATTERS##</b></td>
    </tr>
    <tr>
    <td><b>Technica l Seminar Series &amp; QuikCasts</b>
    <br /></td>
    <td bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_T ECHNICAL_SEMINA R_SERIES##</b></td>
    </tr>
    <tr>
    <td><b>TTI Promotional Emails</b></td>
    <td bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_P ROMO_EMAIL##</b></td>
    </tr>
    </tbody></table>

    <p><br />
    We appreciate you choosing TTI, Inc. as your preferred information source. You should receive your first email within the next 5-7 business days.<br />
    <br />
    Regards,<br />
    <br />
    TTI, Inc.</p>
    <br />
    </td>
    </tr>
    <tr>
    <td colspan="2" class="submitRo w"><div class="style1" align="center"> &copy;2008 TTI, Inc. 2441 Northeast Pkwy, Fort Worth, TX 76106</div></td>
    </tr>
    <tr>
    <td colspan="2" class="submitRo w"><div class="style1" align="center"> </div><br /></td>
    </tr>
    </tbody></table>

    </div>
    </body>
    </html>[/HTML]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Can you change the page which generates the HTML code. If you can, it would be good idea to add some IDs to the table cells which contain these variables. Then you can access them using document.getEle mentById(). If you can't, I can think of other ways to do this.

    Comment

    • jpollack
      New Member
      • Mar 2008
      • 6

      #3
      Originally posted by acoder
      Welcome to TSDN!

      Can you change the page which generates the HTML code. If you can, it would be good idea to add some IDs to the table cells which contain these variables. Then you can access them using document.getEle mentById(). If you can't, I can think of other ways to do this.
      Thank you for your response. I can add IDs to the cells. Like this?

      [HTML]<table style="height: 148px;" border="0" width="667">
      <tbody><tr>
      <td width="177"><b> MarketEye</b></td>
      <td id="market" bordercolor="#F FFFFF" width="480">&nb sp;<b>##CUSTOM_ SUB_MARKETEYE## </b></td>
      </tr>
      <tr>
      <td><b><i>IP&am p;E Matters</i></b></td>
      <td id="ipe" bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_I PE_MATTERS##</b></td>
      </tr>
      <tr>
      <td><b>Technica l Seminar Series &amp; QuikCasts</b>
      <br /></td>
      <td id="technical" bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_T ECHNICAL_SEMINA R_SERIES##</b></td>
      </tr>
      <tr>
      <td><b>TTI Promotional Emails</b></td>
      <td id="promo" bordercolor="#F FFFFF">&nbsp;<b >##CUSTOM_SUB_P ROMO_EMAIL##</b></td>
      </tr>
      </tbody></table>[/HTML]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by jpollack
        Thank you for your response. I can add IDs to the cells. Like this?
        Yes, you can. Now you can access the table cell containing the variable using document.getEle mentById("marke t"). To get the actual contents, you can use innerHTML. This will give you a string. You can use replace() to replace the boolean value with Yes/No.

        Comment

        • jpollack
          New Member
          • Mar 2008
          • 6

          #5
          Originally posted by acoder
          Yes, you can. Now you can access the table cell containing the variable using document.getEle mentById("marke t"). To get the actual contents, you can use innerHTML. This will give you a string. You can use replace() to replace the boolean value with Yes/No.
          I tried this but it did not work. Am I missing a step or is my syntax wrong?

          Thanks again for helping me!!!

          Code:
          <script type="text/javascript">
          
          function changeText(){
          	document.getElementById("market").innerHTML = '##CUSTOM_SUB_MARKETEYE##';
           if (##CUSTOM_SUB_MARKETEYE## == true) 
          {
          str.replace(/##CUSTOM_SUB_MARKETEYE##/, "Yes"));
          }
          else
          {
          str.replace(/##CUSTOM_SUB_MARKETEYE##/, "No"));
          } 
          
          }
          
          window.onload='changeText()' value='Change Text'/>
          </script>

          Comment

          • jpollack
            New Member
            • Mar 2008
            • 6

            #6
            Originally posted by jpollack
            I tried this but it did not work. Am I missing a step or is my syntax wrong?

            Thanks again for helping me!!!

            Code:
            <script type="text/javascript">
            
            function changeText(){
            	document.getElementById("market").innerHTML = '##CUSTOM_SUB_MARKETEYE##';
             if (##CUSTOM_SUB_MARKETEYE## == true) 
            {
            str.replace(/##CUSTOM_SUB_MARKETEYE##/, "Yes"));
            }
            else
            {
            str.replace(/##CUSTOM_SUB_MARKETEYE##/, "No"));
            } 
            
            }
            
            window.onload='changeText()' value='Change Text'/>
            </script>
            This doesn't work either. Am I getting closer?

            Code:
            <script type="text/javascript"><!--
            function changeText(){
            var mystr=document.getElementById("market").innerHTML = '##CUSTOM_SUB_MARKETEYE##';
             if (mystr == true) 
            {
            mystr.replace(/mystr/, "Yes");
            }
            else
            {
            mystr.replace(/mystr/, "No");
            } 
            
            }
            window.onload='changeText()';
            // --></script>

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Try something like:
              [CODE=javascript]<script type="text/javascript">
              function changeText() {
              var market = document.getEle mentById("marke t");
              var mystr = market.innerHTM L;
              mystr = mystr.replace(/true/, "Yes");
              mystr = mystr.replace(/false/, "No");
              market.innerHTM L = mystr;
              }
              window.onload=c hangeText;
              </script>[/CODE]

              Comment

              • jpollack
                New Member
                • Mar 2008
                • 6

                #8
                Thanks so much for continuing to help me! I understand your code perfectly now but it still does not work. I think it is because I am trying to replace a tag (##CUSTOM_SUB_M ARKETEYE##) which is pulling data from a data base. Can you think of anything else I could try? Thanks again. Julie



                Code:
                <p><script type="text/javascript"><!--
                function changeText() {
                  var market = document.getElementById("market");
                  var mystr = market.innerHTML;
                  mystr = mystr.replace(/true/, "Yes");
                  mystr = mystr.replace(/false/, "No");
                  market.innerHTML = mystr;
                }
                window.onload=changeText;
                // --></script>
                </p>
                [HTML]<p>&nbsp;</p>

                <div class="mainDiv" align="center">
                <img src="http://www.mycmdirect. com/webimages/directweb/7/email_header.jp g" alt="TTI - Never Short on Solutions" title="TTI, Inc. - Never Short on Solutions" height="144" width="669" />
                <table style="height: 392px;" align="center" border="0" cellpadding="1" cellspacing="2" width="669">
                <tbody><tr>
                <td colspan="2" class="promoLin e" height="29" width="706">Mar ch 7, 2008 </td>
                </tr>
                <tr>
                <td align="left" valign="top"><p >&nbsp;</p>
                <p>Thank you, ##FIRSTNAME##,< b> </b>for your interest in TTI's free eNewsletter service. </p>
                <table><tbody>< tr><td id="market">##C USTOM_SUB_MARKE TEYE##</td></tr></tbody></table>

                <p><br />
                We appreciate you choosing TTI, Inc. as your preferred information source. You should begin receiving the email subscriptions within the next 5-7 business days.<br />
                <br />
                Regards,<br />
                <br />
                TTI, Inc.</p>
                <br />
                </td>
                </tr>
                <tr>
                <td colspan="2" class="submitRo w"><div class="style1" align="center"> &copy;2008 TTI, Inc. 2441 Northeast Pkwy, Fort Worth, TX 76106</div></td>
                </tr>
                <tr>
                <td colspan="2" class="submitRo w"><div class="style1" align="center"> </div><br /></td>
                </tr>
                </tbody></table>

                </div>[/HTML]

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by jpollack
                  Thanks so much for continuing to help me! I understand your code perfectly now but it still does not work. I think it is because I am trying to replace a tag (##CUSTOM_SUB_M ARKETEYE##) which is pulling data from a data base. Can you think of anything else I could try? Thanks again. Julie
                  I see it's 1 and 0 instead of true/false. Replace true and false in the regexp (/true/ and /false/) with 1 and 0 respectively.

                  Just a note that you could do this on the server-side with whatever language is generating the page and converting the tags to 1 and 0.

                  Comment

                  • jpollack
                    New Member
                    • Mar 2008
                    • 6

                    #10
                    It worked! Thanks so very much for your patience and your assistance! I am eternally grateful!

                    Julie

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      No problem. Glad it worked for you. Post again if you have any more questions.

                      Comment

                      Working...