-1

I have this little javascript code:

<script>
        function editHouse()
        {
            if (edit == false) {
                document.getElementById('edit').style.color='red';
                edit = true;
            }
            else {
                document.getElementById('edit').style.color='blue';
                edit = false;
            }
        }
</script>
    <button id="edit" onclick="editHouse()" type="button">@@@@</button>

Which changes the button text to red and blue everytime the button is pressed. However I need more than that, I need other content on the page to enable after the button has been pressed. An example could be enabling some javascript codes like this:

if (edit == false) {
     <script language="javascript" type="text/javascript" src="js/jquery/jquery-1.5.2.min.js"></script>
     <script language="javascript" type="text/javascript" src="js/jquery/modalpopup.js"></script>
    }

or even enabling whole chunk of codes, maybe including php database connections etc. Is there a way to do that? if I could just write something like:

<script>
    if (edit == false) {
</script>
             <script language="javascript" type="text/javascript" src="js/jquery/jquery-1.5.2.min.js"></script>
             <script language="javascript" type="text/javascript" src="js/jquery/modalpopup.js"></script>
<script>
   }
</script>

But that wasn't the correct way of doing it unfortunatly. Any ideas or suggestions? Thanks in advance.

user3287771
  • 113
  • 2
  • 8
  • That won't work. You need to add the script blocks with JS. And if you want DB connections with a mouseclick, you need AJAX. – putvande Feb 23 '14 at 15:00
  • Why do you need to do *that*? Try to work things around instead, and you'll come up with a solution that doesn't go against the language's grammar – Reger Feb 23 '14 at 15:02
  • How can I add the script blocks with JS? Like a string? – user3287771 Feb 23 '14 at 15:03
  • @Reger it was just an example of what I needed to do to make it easier to understand, I don't know how that would be possible. hmm – user3287771 Feb 23 '14 at 15:04
  • @user3287771 Ok, I understand your point. I don't think that's possible. – Reger Feb 23 '14 at 15:07

1 Answers1

0

You should try to create script element using javascript , refer to this answer : https://stackoverflow.com/a/3248500/3323351

Community
  • 1
  • 1
naguib
  • 85
  • 8