0

I was wondering if anyone can point me in the right direction...I'm new to web development and an having issues with the javascript function run in a new window, instead of the same window/tab that I'm in. I would like it to print out in an element on the page... this is what I have so far...please let me know if more is needed...

html:

<div id="today">
            <script type="text/javascript" src="today.js"></script>
            <p>
                Display todays date and current time here <i>(list of appointments below)</i>
            </p>
            <input id="chbx" type="checkbox" name="edit" value="edit" onchange="dayApptList()">I wish to edit

        </div>

javascript:

time = 0
function waste(){
while (time++ < 8)
    document.write(time + " multiplied by 8 equals " + time * 8 + '<br>')
}
function dayApptList(){
    var checkbox = document.getElementById("chbx");
    // display list of contacts
    if(checkbox.checked){
        waste();
    };
};

thanks for your time and advice

Mike
  • 1
  • 2
  • 1
    Your JavaScript snippet is just your HTML all over again. Also, what do you mean by *"javascript function run in a new window"*? – domsson Apr 07 '17 at 01:00
  • We need to see the definition of the `dayApptList()` function. – Barmar Apr 07 '17 at 01:01
  • As domdom said, you are showing the HTML twice. – Carlos F Apr 07 '17 at 01:01
  • Don't use `document.write()` in functions that run after the page has loaded. It overwrites the current page. – Barmar Apr 07 '17 at 01:01
  • Do you happen to be using document.write?? If so, that's your problem.. – S. Walker Apr 07 '17 at 01:02
  • Instead of `document.write` you should assign to the `innerHTML` of the DOM element that you want the answer to appear in. – Barmar Apr 07 '17 at 01:03
  • thanks, i somehow copied the same code twice.... when i click the check box it runs waste(). i want that, but it reloads the page and just displays waste()... i want it to display the rest of the page still and show the results...preferably without a reload – Mike Apr 07 '17 at 01:04
  • thanks barmar, innerhtml worked ... rookie mistake? – Mike Apr 07 '17 at 01:20

0 Answers0