Jump to content

Recommended Posts

fiddle:

http://jsfiddle.net/v9s6d/

 

on page:

//js (javscripts.js) page:
<script TYPE='text/javascript'>
    function whitespace() {
        var new_html = document.getElementById('new_html').value;
        document.getElementById('bubble').innerHTML = new_html;
    }
</script>



//header stuff:
<script type='text/javascript' src='javascripts.php'></script>

//body stuff:
<p>Welcome to the site <b ID='bubble'>dude</b>
</p>
<INPUT TYPE='text' ID='new_html' VALUE='Enter Text Here' />
<INPUT TYPE='button' ONCLICK='whitespace()' VALUE='Change Text' />

Problem:

When I run the fiddle it works, but when I run the javascript, the dynamic changing doesn't work.

 

Goal:

make a function that can change the bubble data when I click the corresponding link

Link to comment
https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/
Share on other sites

I was at a node.js (MNjs) meet up tonight, and the keynote speaker recommended doing a PJAX function to load the page, because I'm thinking a 1 page architecture with different pages that can be ran in, and out on an onclick..

 

 

Do an ajax request to grab the HTML you want, then just stick it into the element with innerHTML. jQuery makes this easy with their .load method:

$('#bubble').load('b.php');

The above won't load the whole page at once?  I'll have to try the code.

The JS for this would be something like:

//http://www.tizag.com/javascriptT/javascript-innerHTML.php
    function whitespace() {
        var new_html=('#bubble').load('new_html');
//        var new_html = document.getElementById('new_html').value;
        document.getElementById('bubble').innerHTML = new_html;
    }

the menu would be like this:

echo"<div align='left'>
    <ul>
        <li>menu      tester<ul>
            <li><a href='?'>Home</a></li>
            <li><a href='?'>Tools</a>
                <ul>";
                switch(isset($_SESSION['id'])){
                    case TRUE: echo"<li><a href id='new_html' onclick='whitespace()' value='?action=logout'>log out</a></li>"; break;
                    case FALSE: echo"<li><a href id='new_html' onclick='whitespace()' value='?action=login'>log in</a></li>"; break;
                }
                    echo"
                    <li><a href id='new_html' onclick='whitespace()' value='?page=calendar'>calender</a></li>
                    <li><a href id='new_html' onclick='whitespace()' value='?page=batch_mailer'>batch mailer</a></li>
                    <li><a href id='new_html' onclick='whitespace()' value='?page=directory'>directory</a></li>
                </ul>
            </li>
        </ul></li>
    </ul>
</div>
";
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.