Hi everyone, i have this form with 2 divisions. I wanted to retain the current tab after saving records for example, after saving records in tab-2, the tab-2 suppose to appear/retain as current tab. Currently, after clicking submit button the tab will go back to tab-1. Please advise. Thanks.
<form name="ipdprogress" id="ipdprogress" method="post" action="">
<div id="tabs">
<ul>
<li><a href="#tabs-1" >Quarter 1</a></li>
<li><a href="#tabs-2">Quarter 2</a></li>
</ul>
<div id="tabs-1">
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
$con = mysql_connect("localhost","user","");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("p",$con);
$Picid=$_GET['Picid'];
$result = mysql_query("SELECT * FROM progress WHERE Picid='" . $Picid . "' ");
$row= mysql_fetch_array($result);
$Picid = $_GET['Picid'];
$nwQty = "SELECT * FROM progress WHERE Picid = '$Picid'";
$solution = mysql_query($nwQty);
if(isset($_POST['submit'])){
if (mysql_num_rows($solution) == 0){
$sql = "INSERT INTO progress(T11,Selfrating1,Picid) VALUES ('" . $_POST["T11"] . "','" . $_POST["Selfrating1"] . "','" . $Picid . "')";
$result = mysql_query($sql);
}
else {
$sql =("UPDATE progress SET T11='" . $_POST["T11"] . "', Selfrating1='" . $_POST["Selfrating1"] . "' WHERE Picid='" . $Picid . "'");
$result = mysql_query($sql);
echo('Record Updated');
}
$result = mysql_query("SELECT * FROM progress WHERE Picid='" . $Picid . "' ");
$row= mysql_fetch_array($result);
}
?>
<p><b>1.Target</b></p>
<script>
function ocalculateText(el) {
var form = el.form;
var idx = form.Selfrating1.selectedIndex;
if (idx <= 0) {
form.reset();
return;
}
if (form.Selfrating1.value == "Good") {
form.T11.value = "#008000";
} else if (form.Selfrating1.value == "Satisfactory") {
form.T11.value = "#9ACD32";
}
}
</script>
<p>a.i.Self Rating(1st Rating): <select name="Selfrating1" id="Selfrating1" onchange="ocalculateText(this)" value="<?php echo $row['Selfrating1']; ?>" >
<option selected>Please select an option</option>
<option value=Good <?php if($row['Selfrating1']=='Good') { echo "selected"; }?>>Good</option>
<option value=Satisfactory <?php if($row['Selfrating1']=='Satisfactory') { echo "selected"; }?>>Satisfactory</option>
</select>
<input type="color" name="T11" id="T11" onchange="ocalculateText(this)" value="<?php echo $row['T11'];?>"></p>
<input type="hidden" name="Picid" id="Picid" value="<?php echo $row['Picid']; ?>" >
<input type="hidden" name="Progressid" id="Progressid" value="<?php echo $row['Progressid']; ?>">
<td colspan="2"><input type="submit" name="submit" value="Save" class="btnSubmit"></td>
<?php
mysql_close($con);
?>
</div>
<div id="tabs-2">
<?php
session_start();
error_reporting(E_ALL ^ E_NOTICE);
$con = mysql_connect("localhost","user","");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("p",$con);
$Picid=$_GET['Picid'];
$result = mysql_query("SELECT * FROM progress WHERE Picid='" . $Picid . "' ");
$row= mysql_fetch_array($result);
$Picid = $_GET['Picid'];
$nwQty = "SELECT * FROM progress WHERE Picid = '$Picid'";
$solution = mysql_query($nwQty);
if(isset($_POST['submit'])){
if (mysql_num_rows($solution) == 0){
$sql = "INSERT INTO progress(T12,Selfrating2,Picid) VALUES ('" . $_POST["T12"] . "','" . $_POST["Selfrating2"] . "','" . $Picid . "')";
$result = mysql_query($sql);
}
else {
$sql =("UPDATE progress SET T12='" . $_POST["T12"] . "', Selfrating2='" . $_POST["Selfrating2"] . "' WHERE Picid='" . $Picid . "'");
$result = mysql_query($sql);
echo('Record Updated');
}
$result = mysql_query("SELECT * FROM progress WHERE Picid='" . $Picid . "' ");
$row= mysql_fetch_array($result);
}
?>
<p><b>1.Target</b></p>
<script>
function ocalculateText(el) {
var form = el.form;
var idx = form.Selfrating2.selectedIndex;
if (idx <= 0) {
form.reset();
return;
}
if (form.Selfrating2.value == "Good") {
form.T12.value = "#008000";
} else if (form.Selfrating2.value == "Satisfactory") {
form.T12.value = "#9ACD32";
}
}
</script>
<p>a.i.Self Rating(1st Rating): <select name="Selfrating2" id="Selfrating2" onchange="ocalculateText(this)" value="<?php echo $row['Selfrating2']; ?>" >
<option selected>Please select an option</option>
<option value=Good <?php if($row['Selfrating2']=='Good') { echo "selected"; }?>>Good</option>
<option value=Satisfactory <?php if($row['Selfrating2']=='Satisfactory') { echo "selected"; }?>>Satisfactory</option>
</select>
<input type="color" name="T12" id="T12" onchange="ocalculateText(this)" value="<?php echo $row['T12'];?>"></p>
<input type="hidden" name="Picid" id="Picid" value="<?php echo $row['Picid']; ?>" >
<input type="hidden" name="Progressid" id="Progressid" value="<?php echo $row['Progressid']; ?>">
<td colspan="2"><input type="submit" name="submit" value="Save" class="btnSubmit"></td>
<?php
mysql_close($con);
?>
</div>
</form>
Sophia_1 0 Junior Poster in Training
andrevanzuydam 1 Junior Poster in Training Premium Member
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.