Results 1 to 5 of 5

Thread: [RESOLVED] Javascript: Assign innerHTML to DIV

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Resolved [RESOLVED] Javascript: Assign innerHTML to DIV

    Hi,

    As the title suggests, I'm trying to dynamically assign the innerHTML of a DIV tag, but I can't get it to work. I've escaped the characters correctly, but I only get garbage. Here's some code so that you can see what I'm talking about.
    VB Code:
    1. <SCRIPT language="JavaScript">
    2. function ProcessMediumSelection()
    3. {
    4.     document.getElementById('divExpectedReturnDate2').innerHTML = '<script>DateInput(\\'ReturnDate\\', true, \\'DD-MON-YYYY\\')</script>';
    5. }

    Is it getting mixed up by the <script> tag in the HTML I'm trying to assign? When the page is rendered, fragments of the code above is shown at the top. Anyone know how I can do this?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript: Assign innerHTML to DIV

    < = &lt;
    > = &gt;
    & = &amp;
    " = &quot;

    These are the basic replacements to be made.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question mendhak ....

    thanks .... that got rid of the garbage at the top of the page and put the HTML into my DIV tag. But that didn't accomplish what I am ultimately trying to do . I need the script to actually "execute" when placed into the DIV tag. I'll explain.

    I'm using this calendar control ... http://www.dynamicdrive.com/dynamici...oncalendar.htm

    It works fine, but there is no way (or at least I can't figure out) how to assign a date to the control based on a variable value after the page has loaded. The control defaults to today's date or you can specify a date when the page is initially loaded. But my user wants to be able to increment the value in one date control by 1 month based on the value in another date control. So, if the first control has a date of Dec 3, 2005, she wants the other control to show Jan 3, 2006. I can't find a way to pass a value to the control after it has been initially created. The closest thing I found on the web was here ...
    http://www.dynamicdrive.com/forums/a...hp/t-2746.html

    There should be a WAY to do this. Anybody up for a Saturday challenge to figure this out? I hope so, because I've spent too much of my Saturday trying to do so.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Javascript: Assign innerHTML to DIV

    You need to split the script end tag into two parts. Some HTML processors recognize it as the end of your actual script.
    Code:
    document.getElementById('divExpectedReturnDate2').innerHTML =
      '<sc'+'ript>DateInput(\'ReturnDate\', true, \'DD-MON-YYYY\')</scr'+'ipt>';
    However, I'm not sure if this means the browser will actually execute the new code. Besides, why would you WANT such confusing code?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Unhappy Corned Bee ...

    Thanks for the reply. Unfortunately, the browser still didn't execute the script.
    why would you WANT such confusing code?
    It's not that I want confusing code ... I just want something that will work. My problem is probably my choice of the calendar control ( http://www.dynamicdrive.com/dynamici...oncalendar.htm ). I started off using it initially in my project and it's too late to change now because this project will be moving to production soon. I would have encountered this problem earlier, but the user just asked for this feature last week. Looks like I'll have to tell her that it can't be done , although it seems like a very simple thing to do (i.e., display one date in a calendar based on a date in another calendar). But maybe one of you guys (or gals) reading this will take a look at my "12-03-2005 02:27 PM" post above and try to figure out how to do this before I tell the user the bad news. Nothing wrong with having hope, right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width