Jump to content

form submission to reload div


woodplease

Recommended Posts

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>

Link to comment
Share on other sites

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.