Sunday, December 13, 2015

Re: calling html file from within javascript

Hello,

although this is barelyDjango related, here are some notes.

From MDN[1]: Note: as document.write writes to the document stream, calling document.write on a closed (loaded) document automatically callsdocument.open which will clear the document.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Document/write

On Dec 14, 2015 1:22 AM, "Gary Roach" <gary719_list1@verizon.net> wrote:
I use javascript in my  main.html (top template) to control the access to several buttons. The buttons call a javascript function. This setup works exactly as I wish except the buttons still don't really do anything. I need to have each button load a different template. The pertinent script is:

        <script type="text/javascript">
            "use strict"
            var bn = ""
            function buttoncontrol(bn){
                var i = 0;
                var bx = "";
                var x = []; /*array*/
                if (bn=="resetDone")
                    {
                    for (var i = 0; i < 4; i++)
                        {
                        bx= "b" + (i+1);
                        document.getElementById(bx)
                            .removeAttribute("disabled");
                        }
                    return
                    }
                else {
                    for (var i = 0; i < 4; i++)
                        {
                        bx= "b" + (i+1);
                        document.getElementById(bx)
                            .setAttribute("disabled", "true");
                        }
                switch(bn) {
                    case "b1":
                        document.write("<a href=                'welcome.html'>'Welcome.html'</a>");
                         break;
                    case "b2":
                        break;
                    case "b3":
                        break;
                    case "b4":
                        break;
                    default:
                        document.write("fell out the bottom");
                        }
                return;
                    }
                }

        </script>

The code works till it hits the document.write statement and freezes. This just plain doesn't work. What would. I want to keep this approach, so I need an alternative to the  document.write statement.

Both my main.html and my welcome.html are in the same template directory. I bypassed the button during development and the two pages worked well together.

Django 1.8
Python 3.4

Gary R.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/566E0BC0.8020100%40verizon.net.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACczBU%2Bbdr%3DNT6Jp2dqC25mzO%3DrZccQK2b-gK05ACPLgJFmGug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment