Jump to content

[SOLVED] Refresh after inserting


timmah1

Recommended Posts

Hello,

 

I have a page (http://www.cheezyfries.net/plumbing/new_job.php) that you can input a new job with certain fields.

 

In the drop down menus, that are generated from the database, if your item isn't listed, you can list it by clicking a link that pops up a new window, you input the new item, and then close the window.

 

How can I make it so that just that field (drop-down menu) gets refreshed to show the new item without refreshing the whole page?

 

Any help would be greatly appreciated.

 

Thanks in advance

Link to comment
Share on other sites

AJAX is the only thing I know of dynamic enough to repopulate without a page refresh.

 

Why do you need to search the database for many values to find one extra value, when you already know the one extra value? That takes extra bandwidth, where as this non-Ajax method will not, and produce the same result.

Link to comment
Share on other sites

OK, I found it.

 

main page:

<script type="text/javascript">
function loadWindow(popurl){
var winpops=window.open(popurl,"subWindow","width=400,height=500,status,scrollbars")
}
</script>



<form name="form1">
<select name="select1"> 
	<option value="v1">v1</option>
	<option value="v2">v2</option>
	<option value="v3">v3</option>
</select>
<a href="javascript:loadWindow('page.html');">Load Window</a>
</form>

 

pop-up window:

<script type="text/javascript">
function update(){
var vals = opener.document.form1.select1.innerHTML;
var newVal = document.getElementById('myV').value;
var finalVal = vals+'<option value="'+newVal+'">'+newVal+'</option>';
opener.document.form1.select1.innerHTML = finalVal;
document.theForm.submit();
}
</script>

<form name="theForm">

<input type="text" id="myV" />
<input type="button" value="Save" onclick="update();" />

</form>

Link to comment
Share on other sites

That works great, but how does that populate the database?

 

The drop-down menu is populated from information in the database. The pop-up needs to insert the new information into the database, and then on the main page, it needs to re-populate the drop-down with the new information.

 

does that make sense?

Link to comment
Share on other sites

Here's the main page

<span class="style1">Job Type Not Listed?<br /><a href="javascript:loadWindow('pop_job_type.php');">Click Here</a>

 

Here is the pop-up

if($_POST['enter'] == "yes"){
?>
<script type="text/javascript">
function update(){
var vals = opener.document.form1.job_type.innerHTML;
var newVal = document.getElementById('name').value;
var finalVal = vals+'<option value="'+newVal+'">'+newVal+'</option>';
opener.document.form1.job_type.innerHTML = finalVal;
document.theForm.submit();
}
</script>
<?php


include("config.php");
$insert = mysql_query("insert into job_type values ('NULL','".$_POST["name"]."')")
or die("Sorry, there was a problem inserting the job type ".mysql_error());

echo "Job Type inserted into database";
echo "<br><a href=\"javascript:window.close();\">Close This Window</a>";
}

 

I have the action within itself. It inserts into the database with no problem, but it's not automatically updating the drop down

 

You can see here with the code above http://www.cheezyfries.net/plumbing/new_job.php

Link to comment
Share on other sites

Pesonally, i think you'd make it much more user friendly if you did use some AJAX - i would have it set up so that the link showed a small text field just below the drop down box, with a button. Once the button is clicked, you could update the drop-down box, and use AJAX to add the option to the database.

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.