I've been looking for a script that seems relatively simple but I can't find it anywhere! I guess I just don't know what to call it.
Basically I just want to be able to have 2 text boxes on a page, and when you click on a link in one box, it changes the content in the second box. It sounds like what iframes did way back when, but I just HATE iframes.
Is there a javascript equivalent that anyone knows about?
You can do that using AJAX, that is if the content you want to display reside on your database or you want to load a page on that particular div but if not, you can write the content of your second box using javascript alone.
i.e. (JAVASCRIPT)
function changeContent(dvalue) {
var div1 = document.getElementById('DIV1_ID');
if(dvalue == 'RADIO_VALUE1') {
div1.innerHTML = "YOUR CONTENT HERE. YOU CAN INCLUDE html TAGS ";
} else {
div1.innerHTML = "FIRST RADIO BUTTON CONTENT WILL BE DISPLAYED HERE";
}
return;
}
i.e. (JAVASCRIPT AND AJAX)
function AjaxRequest()
{
if (window.XMLHttpRequest)
{
// code for IE7 , Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function changeContent(dvalue) {
var div_id = document.getElementById('div_id');
xmlHttp = AjaxRequest();
xmlHttp.open("GET", dvalue, true);
xmlHttp.onreadystatechange = function () {
if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
div_id.innerHTML = xmlHttp.responseText;
}
}
xmlHttp.send(null);
return;
}
NOTE: make sure that the value of your radio button is a link for this to work
Bookmarks