Q695 Posted March 25, 2014 Share Posted March 25, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/ Share on other sites More sharing options...
kicken Posted March 25, 2014 Share Posted March 25, 2014 Off hand I see that your script tag references javascripts.php but your comment says the code is in javascripts.js. Make sure you have the correct filename. The external script file should not have any <script> tags either. Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1473885 Share on other sites More sharing options...
Q695 Posted March 26, 2014 Author Share Posted March 26, 2014 Stripping the <script> from the js solved it . Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1473889 Share on other sites More sharing options...
Q695 Posted March 26, 2014 Author Share Posted March 26, 2014 Now I need to get it to load various HTML into the javascript to produce in the "bubble". Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1473891 Share on other sites More sharing options...
Q695 Posted March 27, 2014 Author Share Posted March 27, 2014 (edited) Think similar to iframe for this example: viewing: a.php click to load: b.php loads: b.php text chancges: a.php goes away, then b.php is the only one visible Edited March 27, 2014 by Q695 Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1474226 Share on other sites More sharing options...
kicken Posted March 28, 2014 Share Posted March 28, 2014 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'); Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1474240 Share on other sites More sharing options...
Q695 Posted March 28, 2014 Author Share Posted March 28, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1474245 Share on other sites More sharing options...
Q695 Posted March 28, 2014 Author Share Posted March 28, 2014 (edited) I figured out this code is compliant, but it shows nothing on the browser window: <script type='text/plain' src='applets/b.php'></script> Edited March 28, 2014 by Q695 Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1474248 Share on other sites More sharing options...
Q695 Posted March 28, 2014 Author Share Posted March 28, 2014 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> "; Quote Link to comment https://forums.phpfreaks.com/topic/287273-fiddle-works-but-html-doesnt/#findComment-1474249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.