...

View Full Version : Refresh Value from popup page to main page



LiveWire
05-02-2006, 10:53 AM
I created a quick slide show of what I need.

What I'm looking to do is have a page that has a link to add a new value into the database. When you click the link, a small popup will be shown with a textfield asking you for the value. After typing the value and pressing the save button. The popup box will close and the main page will have the value shown without refreshing the page.

How can I achive this? I know you would have to use ajax maybe? Or some type of onload method, though I don't know.

See attachment for clarification. Thanks!

LiveWire
05-02-2006, 10:58 AM
I should note that I know how to do this on one page.

Main.html


<html>
<head>

<script language="Javascript">
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;

// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}

// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}

self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}

entrytitle=document.getElementById("entrytitle").value;
entrytext=document.getElementById("entrytext").value;

qstr = 'entrytitle='+entrytitle+'&entrytext='+entrytext;
self.xmlHttpReq.send(qstr);
}

function updatepage(str){
document.getElementById("mydiv").innerHTML=str;
}
</script>
</head>
<body>
<form>
Title: <input id="entrytitle" type="text"><br>
Text: <input id="entrytext" type="text"><br>
<input type="button" value="Submit" onclick="xmlhttpPost('process.php');">
</form>

<div id="mydiv"></div>

</body>
</html>


process.php


<?php

echo $HTTP_POST_VARS['entrytitle'];
echo $HTTP_POST_VARS['entrytext'];

?>


I just don't know how to display this on the main page from the popup menu.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum