woodplease Posted July 11, 2012 Share Posted July 11, 2012 hey. i have a webpage with a menu so that when a link is clicked, a div on the same page loads the links content into it. This works fine. The content of the div is a web form, that when submitted, reloads the page to add the content to the database. the problem is that when the form is submitted, the whole page is re-loaded instead of the div. how can i change it so that when the form(in the div) is submitted, the page is only reloaded in the div? The Menu code: <script type="text/javascript"> var loadedobjects="" var rootdomain="http://"+window.location.hostname function ajaxpage(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } page_request.open('GET', url, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs(){ if (!document.getElementById) return for (i=0; i<arguments.length; i++){ var file=arguments[i] var fileref="" if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1){ //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1){ //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!=""){ document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } </script> </head> <center> <div id="leftcolumn"> <a href="javascript:ajaxpage('new_cat.php', 'rightcolumn');">New Category</a> <a href="javascript:ajaxpage('new_album.php', 'rightcolumn');">New Album</a> <a href="javascript:ajaxpage('new_user.php', 'rightcolumn');">New User</a> </div> <div id="rightcolumn"><h3>Choose a page to load.</h3></div> The form code: <?php include "../dbconnect.php"; include "../menu.php"; if (isset ($_POST['cat_name'])){ $cat_name = mysql_real_escape_string($_POST['cat_name']); } if (isset ($_POST['cat_desc'])){ $cat_desc = mysql_real_escape_string($_POST['cat_desc']); } ?> <head> <script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script> </head> <center> <?php if (isset($_POST['submit'])) { mysql_query ("INSERT INTO category (cat_name, cat_desc) VALUES ('$cat_name', '$cat_desc')"); ?> <div id="txtHint"> <h1>Category added</h1><br /><br /><br /></div> <a href='javascript:javascript:history.go(-2)'>BACK</a> <?php } else { ?> <div id="stylized" class="login"> <h1>Create new Category</h1> <p>Please enter details for the new Category</p> <form id="new_category" method="post" action="new_cat.php"> <label>Category Name </label><input type="text" name="cat_name" size="50" /> <label>Description</label><textarea rows="10" cols="40" name="cat_desc"></textarea> <button type="submit" name="submit" >Add New Category</button> <?php } ?> </center> Quote Link to comment https://forums.phpfreaks.com/topic/265514-form-submission-to-reload-div/ 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.