SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.write(my_var); refuses to change!! NEED help. even insults are welcome!

    oh wise ones... your guidance is desperately needed!

    any thoughts at all PLEASE would be greatly appreciated!! even insults are welcome!! this should be easy as pie, but I've been banging my head on the wall and going around in circles all morning! spent a long time on "the Google" looking for my problem. all I found was maybe I shouldn't be using document.write, but found no alternative. plus it works (the first time through anyways).


    I have a pop up window where users schedule an event to post on a calendar. events occur once, or repeat (say weekly, for example).

    here is what I need the script to do:
    check a drop down form to see if user wants event to repeat or not. default is not. this part is working fine.
    if event repeats we HIDE a time input form. this part is working fine.
    if event does NOT repeat we SHOW the time input form. this part working fine.

    but what I thought would be the simplest part is not working. my_var is just a lousy string that I want to write. it should show "End Date" if event does not repeat, or "Repeat Until" if event does repeat. but I can't get the damn thing to work. I know just about zero javascript. I understand it is browser side, not server side and that's about it.

    sorry about no link for you guys to try the script yourselves. this thing is running on my localhost. not ready for prime-time :-)

    THANK YOU for your valuable time. here is the offending code:

    <head>
    <script type="text/javascript">
    <!--

    repeat_var="End Date:";

    function writebox(form) {
    if (form.repeat.value=='0') {
    repeat_var="End Date:";
    document.getElementById("dTimeE").style.visibility = "visible";
    } else {
    repeat_var="Repeat Until:";
    document.getElementById("dTimeE").style.visibility = "hidden";
    }
    }
    //-->
    </script>
    </head>

    <body>
    <td>
    <select name="repeat" title="Select how often" id="repeat" onchange="writebox(this.form)">
    <option value="0"<?php echo (!$_POST["repeat"]) ? ' selected="selected">' : ">"; echo $xx["evt_none"]; ?></option>
    <option value="1"<?php echo ($_POST["repeat"] == "1") ? ' selected="selected">' : ">"; echo $xx["evt_daily"]; ?></option>
    <option value="2"<?php echo ($_POST["repeat"] == "2") ? ' selected="selected">' : ">"; echo $xx["evt_weekly"]; ?></option>
    <option value="3"<?php echo ($_POST["repeat"] == "3") ? ' selected="selected">' : ">"; echo $xx["evt_monthly"]; ?></option>
    <option value="4"<?php echo ($_POST["repeat"] == "4") ? ' selected="selected">' : ">"; echo $xx["evt_yearly"]; ?></option>
    </select>
    </td>

    <td><script type="text/javascript">document.write(repeat_var);</script></td>

    <td id="dTimeE"<?php echo $hidden; ?>><input type="text" title="click clock icon or enter HH:MM XM" name="end_time" id="end_time" value="<?php echo $_POST["end_time"]; ?>" size="6" /><a href="#" onclick="tPicker('end_time')"><img src="images/flipped_clock.png" alt="End Time" /></a>

    </body>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A document.write statement runs once while the page is first loading - since you have server side code there the document.write is better replaced by a PHP echo statement which serves exactly the same purpose.

    If you want to actually update the page after it has loaded you need to use either innerHTML or the appropriate DOM commands. If you want to update a part of something you have already updated or part of a table then even innerHTML doesn't work.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    so very close now !!

    THANK YOU SIR !!

    oh so very close now. script is working great EXCEPT for initial page load - there the variable is empty and nothing is printed.
    new code:
    function writebox(form) {
    var labelTD = document.getElementById("otherLabel");
    if (form.repeat.value=='0') {
    labelTD.innerHTML="End Date";
    document.getElementById("dTimeE").style.visibility = "visible";
    } else {
    labelTD.innerHTML="Repeat Until";
    document.getElementById("dTimeE").style.visibility = "hidden";
    }
    }

    <td id="otherLabel">&nbsp;</td>

    tried this to get page to load with "End Date", but no dice. can you educate me just one more time me please...

    var labelTD = document.getElementById("otherLabel");
    labelTD.innerHTML="End Date";

    function writebox(form) {
    var labelTD = document.getElementById("otherLabel");
    if (form.repeat.value=='0') {
    labelTD.innerHTML="End Date";

    document.getElementById("dTimeE").style.visibility = "visible";
    } else {
    labelTD.innerHTML="Repeat Until";
    document.getElementById("dTimeE").style.visibility = "hidden";
    }
    }

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OR is that what document.write is for... just the page load. should I put that back in? is that best practice?


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
  •