Echo value back on postback - php

I have five dropdown list which depending on the selection the display changes to block.
The problem comes when values are posted back. The drop down list does not show the values. This likely because of javascript that by default displays as none the drop down list. The javascript listens for onclick. Here is part of the javascripts:
function changeOptions() {
var form = window.document.getElementById("frm1");
var sv = window.document.getElementById("sv");
var sv2= window.document.getElementById("sv2");
var sv3 = window.document.getElementById("sv3");
var sv4= window.document.getElementById("sv4");
var sv5 = window.document.getElementById("sv5");
if (form.radioButton1.checked) {
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "none";
sv.style.display = "block";
//sv.selectedIndex =0;
else if (form.radioButton5.checked) {
sv.style.display = "none";
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "block";
sv5.selectedIndex = 0;
}
}
window.document.getElementById("radioButton5").onclick = changeOptions;
The dropdown menu is populated from my database. Below is the code. There are five of them The display:none changes to block depending which radio button is clicked.
<select style="width:200px; **display:none**" name="pGroup" id="sv" >
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup'])?$_GET['pGroup']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 3 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
.
.
.
.
<select style="width:200px; **display:none**" name="pGroup5" id="sv5">
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup5'])?$_GET['pGroup5']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 7 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
I am a novice in this and would like help on how to retain the value on my dropdownon postback.

per comment above, would need to see more code to be exact, but here is a pseudo version that you may be able to adapt;
<body
<?PHP if(isset($_GET['selectedGroupId'];)){ ?>
onload='window.document.getElementById("radioButton<?PHP echo $_GET['selectedGroupId']; ?>").click()'
<?PHP } ?>
>
replace $_GET['selectedGroupId'] with your fieldname/id
see if that gets you on the right track

Related

Option selected using ajax and php

I have some dropdown select as below
<div class="dep" style="display: inline;">
<select name="dep" id="dep" class="drp" style="width:19%;">
<option value="">Choose departament</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
$selected = "";
if(isset($_POST['dep'])){
if ($_POST['dep'] == $row['D_id']) {
$selected = "selected='selected'";
}
}
echo '<option value="'.$row["D_id"].'" '.$selected.' >'.$row['Emri'].'</option>';
}
}else{
echo '<option value="">No Departaments</option>';
}
?>
</select>
</div>
The below dropdown filled when i select department using ajax
<div class="dega" style="display: inline;">
<select name="dega" id="dega" class="drp" style="width:19%;">
<option value="">Choose Sector </option>
</select>
</div>
to be filled need the follows :
ajax:
<script type="text/javascript">
$(document).ready(function(){
$('#dep').on('change',function(){
var dep_id = $(this).val();
if(dep_id){
$.ajax({
type:'POST',
url:'ajaxData.php',
data:'D_id='+dep_id,
success:function(html){
$('#dega').html(html);
}
});
}else{
$('#dega').html('<option value="">choose departament</option>');
}
});
});
And the ajaxData.php file where the ajax code take the values
include('dbConfig.php');
if(isset($_POST["D_id"]) && !empty($_POST["D_id"])){
$query = $db->query("SELECT * FROM deget WHERE D_id = ".$_POST['D_id']."");
$rowCount = $query->num_rows;
if($rowCount > 0){
echo '<option value="">Choose sector</option>';
while($row = $query->fetch_assoc()){
$sel = "";
if (isset($_POST['dega'])) {
if ($_POST['dega'] == $row['Dg_id']) {
$sel = "selected='selected'";
}
}
echo '<option value="'.$row['Dg_id'].'" '.$sel.'>'.$row['Emri'].'</option>';
}
}else{
echo '<option value="">No sectors revalent to department</option>';
}
}
Everything works fine except something.When i post the button all my dropdown are selected because i use selected='selected' EXCEPT the second dropdown choose sector and that because i have used ajax.I have tried on php file that took with ajax to make the option selected but it does not works.Any idea?
i find my problem and the solution is :
<div class="dega" style="display: inline;">
<select name="dega" id="dega" class="drp" style="width:19%;">
<?php if(isset($_POST['kot'])){
//Include database configuration file
include('dbConfig.php');
//Merr te dhenat e degeve perkatese te departamentit te selektuar
$query = $db->query("SELECT * FROM deget WHERE D_id = ".$_POST['dep']."");
//Rreshtat e querit
$rowCount = $query->num_rows;
//Mbush dropdown e degeve
if($rowCount > 0){
echo '<option value="">Zgjidh Degen</option>';
while($row = $query->fetch_assoc()){
$sel = "";
if($_POST['dega'] == $row['Dg_id']){
$sel = "selected='selected'";
}
echo '<option value="'.$row['Dg_id'].'" '.$sel.'>'.$row['Emri'].'</option>';
}
}else{
echo '<option value="">Nuk ka dege perkatese</option>';
}
}else{?>
<option value="">Selekto Degen </option>
<?php }?>
</select>
</div>

Alternative for huge database list

Ok so I have three tables which contains list World's countries their states and their cities for my registration form. The problem is that the list of the cities is too huge. It contains 48,314 entries in total. So my site is getting hanged and the browser is showing messages to stop script. I am using mozilla for browser purpose.
This is the code I am using to get the cities, states and countries:
$country = "SELECT * FROM countries";
$country = $pdo->prepare($country);
$country->execute();
$state = "SELECT * FROM states";
$state = $pdo->prepare($state);
$state->execute();
$city = "SELECT * FROM cities";
$citq = $pdo->prepare($city);
$citq->execute();
This is my jQuery code:
$(document).ready(function () {
$("#country").change(function() {
if ($(this).data('options') == undefined) {
$(this).data('options', $('#state option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#state').html('<option value="">Select State</option>').append(options);
});
$("#state").change(function() {
if ($(this).data('options') == undefined) {
$(this).data('options', $('#city option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#city').html('<option value="">Select City</option>').append(options);
});
});
This is my HTML:
<select name="country" id="country">
<option value="">Select Country</option>
<?php while($i = $country->fetch()){ extract($i); ?>
<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
<?php } ?>
</select>
<select name="state" id="state">
<option value="">Select State</option>
<?php while($j = $state->fetch()){ extract($j); ?>
<option value="<?php echo $country_id; ?>" data="<?php echo $id; ?>"><?php echo $name; ?></option>
<?php } ?>
</select>
<select name="city" id="city">
<option value="">Select City</option>
<?php while($k = $citq->fetch()){ extract($k); ?>
<option value="<?php echo $id ; ?>" data="<?php echo $state_id; ?>"><?php echo $name ; ?></option>
<?php } ?>
</select>
Now can anyone please help me getting a solution as to how I can load it completely smoothly without getting my site hanged whenever the page is refreshed?
You could load the states and cities dynamically once the "parent" selection is made. This would reduce the amount of data.
No clear code because I think you know what you are doing, but the idea:
-> [html] select
-> [js] onChange call php with ajax
-> [php] SQL select states where country="chosencountry"
-> [js] update form/selectbox
EDIT: (code)
JS:
<script>
function BuildSelectbox(job,parent) {
try { req = window.XMLHttpRequest?new XMLHttpRequest():
new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { /* No AJAX Support */ }
req.open('get','subselects.php?job='+job+'&parent='+parent);
/* let the php echo the resultvalue */
req.onreadystatechange = function() {
handleResponse(div);
};
req.send(null);
}
function handleResponse(div) {
if ((req.readyState == 4) && (req.status == 200)) {
document.getElementById(job).value=req.responseText;
}
}
</script>
PHP part: (subselects.php)
<?
if ($_GET["job"]=="states") {
// assuming there is a key country in states
$state = "SELECT * FROM states where country=".$_GET["parent"];
$state = $pdo->prepare($state);
$state->execute();
} else {
// assuming there is a key state in cities
$city = "SELECT * FROM cities where state=".$_GET["parent"];
$citq = $pdo->prepare($city);
$citq->execute();
}
// echo the whole selectbox
echo '<select id="'.$_GET["job"].'">';
// put the option loop from your queryresult here
echo '</select>';
?>
HTML:
<div id="countries" onChange="BuildSelectbox('states',this.selectedIndex);>
<select name="country" id="country">
<option value="">Select Country</option>
<?php while($i = $country->fetch()){ extract($i); ?>
<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
<?php } ?>
</select>
</div>
<div id="states"></div>
<div id="cities"></div>
This dynamically generates full selectboxes and puts them into the empty divs "states and "cities". Of course you need to output the selectbox in the php code. Parent of states is country and parent of cities is states. Hope this explains it.

Retaining dropdown values after submitting form using GET method

I am using dropdown to select values, and after I click the submit button, my values change. Please help me retain the selected values. Using POST method I have got the solution, but I want to use with GET method. Is it possible?
1.) 1st select stmt:
<form action="" method="GET">
<select name="sort" >
<option value="inc_patientName">Patient Name</option>
<option value="inc_date">Date</option>
<option value="inc_status">Status</option>
<option value="inc_patientAge">Age</option>
</select>
<input type="submit" name="GETREPORT" value="Get Report"/>
if ($_GET)
{echo"hi";}
</form>
2.) 2nd select with while
<?php
//Selecting ward from table ward master
$sql = "SELECT ward_name,ward_id FROM ward_master";
$result = mysql_query($sql);
echo "<select name='ward'>";
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['ward_id'] . "'>" . $row['ward_name'] . "</option>";
}
echo "</select>";
?>
3.) 3rd select with javascript:
<select name="daydropdown" id="daydropdown" ></select>
<select name="monthdropdown" id="monthdropdown"></select>
<select name="yeardropdown" id="yeardropdown"></select>
<script type="text/javascript">
populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
Javascript code:
<script type="text/javascript">
var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];
function populatedropdown(dayfield, monthfield, yearfield)
{
var today=new Date()
var dayfield=document.getElementById(dayfield)
var monthfield=document.getElementById(monthfield)
var yearfield=document.getElementById(yearfield)
for (var i=1; i<=31; i++)
dayfield.options[i]=new Option(i, i)
dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
for (var m=0; m<12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
var thisyear=1999
for (var y=0; y<45; y++){
yearfield.options[y]=new Option(thisyear, thisyear)
thisyear+=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}
</script>
try
if(isset($_GET['sort'])) {
echo $_GET['sort'];
}
and get selected index
<option value="inc_patientName" <?php if (isset($_GET['sort']) && $_GET['sort'] == "inc_patientName") echo 'selected="seleceted"'; ?>>Patient Name</option>
and so on for all options values match
For 2nd dropdown:-
while ($row = mysql_fetch_array($result)) {?>
<option value="<?php echo $row['ward_id'];?>" <?php if (isset($_GET['sort']) && $_GET['sort'] == $row['ward_id']) echo 'selected="seleceted"'; ?>><?php echo $row['ward_name'];?></option>
<?php }
use it like this... it myt work.
<select name="ward">
<?php
$sql = "SELECT ward_name,ward_id FROM ward_master";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
if ($_GET['ward']==$row["ward_id"]) {
echo '<option selected="selected" value='.$row["ward_id"].'>'.$row["ward_name"].'</option>';
} else {
echo '<option value='.$row["ward_id"].'>'.$row["ward_name"].'</option>';
}
}
?>
</select>
You can do something like this:
<select name="sort" >
<option value="inc_patientName"<?php if ($_GET['sort'] == 'inc_patientName') echo ' selected="seleceted"'; ?>>Patient Name</option>
<option value="inc_date"<?php if ($_GET['sort'] == 'inc_date') echo ' selected="seleceted"'; ?>>Date</option>
<option value="inc_status" <?php if ($_GET['sort'] == 'inc_status') echo ' selected="seleceted"'; ?>>Status</option>
<option value="inc_patientAge"<?php if ($_GET['sort'] == 'inc_patientAge') echo ' selected="seleceted"'; ?>>Age</option>
</select>
Try this:
Use this function in ur script:
function setday(id,elementname)
{
document.getElementById(elementname).value=id;
}
Use this in ur php form, Repeat the same code for year and month dropdowns:
if (isset($_GET['daydropdown']))
{
echo "<script type='text/javascript'>setday('".$_GET['daydropdown']."','daydropdown')</script>";
}

how to set the selected value tag <select> html from database in php?

I'm trying to create a drop down menu that will select a value that is stored in the database. here's the code :
require 'koneksi.php';
$sql_select = "SELECT * FROM supplier";
$hasil = mysql_query($sql_select);
if(!$hasil) {
echo "data supplier not found ".mysql_error();
}
$id = $_GET["id"];
$hasil2 = mysql_query("SELECT * FROM brg_supplier WHERE id_brg=".$id);
$data = mysql_fetch_array($hasil2);
if($hasil2) {
$supplier = $data['nama_supplier'];
}
<select name="supplier">
<option value="">---pilih supplier---</option>
<?php
while($baris = mysql_fetch_array($hasil)){
?>
<option value="<?php $baris['nama_supplier'] ?>" <?php if ($supplier==$baris['nama_supplier']) echo 'selected="selected"'; ?> > <?php echo $baris['nama_supplier']; ?> </option>;
<?php }?>
</select>
the problem is my code creates a dropdown with nothing selected. here's the screenshot : link
i've tried all the solutions in the stackoverflow. but the dropdown value still nothing selected. i know that it has to be something simple that i am missing but seriously i cannot figure it out. please anyone help, thanks!
I think the problem lies in this line:
<option value="<?php $baris['nama_supplier'] ?>" <?php if ($supplier==$baris['nama_supplier']) echo 'selected="selected"'; ?> > <?php echo $baris['nama_supplier']; ?> </option>;
You're missing an echo and it looks funny :/
Try instead:
<option <?php $val=$baris['nama_supplier']; echo "value='$val'"; if($supplier==$val) echo "selected='selected'>";echo $val;?> </option>;
Try this way..
$sel="select f.*,c.category from final f, category c where f.category_id=c.id and f.id='$id'";
$data=mysql_query($sel);
$res=mysql_fetch_assoc($data);
<select name="cat">
<?php
$sql = mysql_query("SELECT * FROM category");
while ($row = mysql_fetch_array($sql)){
if($row['id'] == $res['category_id']){
echo '<option value="'.$row['id'].'" selected="selected">'.$row['category'].'</option>';
}else{
echo '<option value="'.$row['id'].'">'.$row['category'].'</option>';
}
}
?>
</select>
Try this out
require 'koneksi.php';
$sql_select = "SELECT * FROM supplier";
$hasil = mysql_query($sql_select);
if(!$hasil) {
echo "data supplier not found ".mysql_error();
}
$id = $_GET["id"];
$hasil2 = mysql_query("SELECT * FROM brg_supplier WHERE id_brg=".$id);
$data = mysql_fetch_array($hasil2);
if(mysql_num_rows($hasil2) > 0) {
$supplier = $data['nama_supplier'];
}
<select name="supplier">
<option value="">---pilih supplier---</option>
<?php
while($baris = mysql_fetch_array($hasil)){
?>
<option value="<?php echo $baris['nama_supplier'] ?>" <?php if ($supplier==$baris['nama_supplier']) {echo 'selected="selected"';} ?> > <?php echo $baris['nama_supplier']; ?> </option>;
<?php }?>
</select>
<option value="<?php $baris['nama_supplier'] ?>
should be
<option value="<?php echo $baris['nama_supplier'] ?>
I spent some time trying to find the best solution for this, and came up with a tiny little jQuery code.
First of all you should be using PDO or mysqli instead of mysql, since it's deprecated. Let's assume you've fixed that.
Inside the <form> tag, add an <input type="hidden"/> so that it can storage your database value, for example:
HTML
<form>
<input id="valueFromDatabase" type="hidden" value="<?php echo $stringFromDB ?>"/>
</form>
Note: in this case, $stringFromDB is a variable that holds your query's return from DB.
So now we have the value of our database inside our HTML code. Now we just need to check if any of the options inside the <select> tag is equal to this value. We'll be doing it with jQuery:
jQuery
$( document ).ready(function() {
$('option').each(function(){
if (this.value == $('#valueFromDatabase').val()){
this.setAttribute('selected', 'selected');
}
});
});
What's happening here? We are telling to jQuery to analyze all the <option> tags in the HTML and compare its value with our value from database; if its equal, we add the selected attribute to the equivalent <option>.
You can it working here (used a calendar example).
Hope that helps!

How to hide previous table rows that were shown based on previous search

The idea of the following code is that the user will search based on maintenance operation No, operation type, the member who performs the operation, or the employee whose PC needs maintenance. When the user selects, for example, the operation type, a drop-down menu will show up and then he selects the type. After that a table of maintenance information will show up. For example, the user selects the type Printing. The table will show the following information:
Operation No, Member Name, Employee Name, Maintenance Type
1001, Adem, John, Printing
1003, George, Smith, Printing
1010, William, John, Printing
The problem that I am facing is when the user selects search by operation no, for example, and he selects the operation no is 1001, the rest of the rows (1003 and 1010 that were shown based on the previous search) are still shown up (they must be hidden because they do not match with the search type).
The code is
<script>
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
if (current_value == "OpNo") {
document.getElementById("operationno").style.display = "block";
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpTyp") {
document.getElementById("MainType").style.display = "block";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
else if (current_value == "OpMem") {
document.getElementById("MemName").style.display = "block";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "none";
}
else if (current_value == "OpEmp"){
document.getElementById("MemName").style.display = "none";
document.getElementById("operationno").style.display = "none";
document.getElementById("MainType").style.display = "none";
document.getElementById("EmpName").style.display = "block";
}
else if (current_value == "blank") {
document.getElementById("MainType").style.display = "none";
document.getElementById("MemName").style.display = "none";
document.getElementById("EmpName").style.display = "none";
document.getElementById("operationno").style.display = "none";
}
}
</script>
<form name="f1" action="FollowOperations.php" method="post">
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="OpNo">Operation No</option>
<option value="OpTyp">Operation Type</option>
<option value="OpMem">Maintenance Member</option>
<option value="OpEmp">Employee</option>
</select><br>
<input class="tb10" type="text" id="operationno" size="4" style="text-align: center" style="display: none">
<select id="MainType" style="display: none">
<option value="blank">Choose</option>
<option value="printing">Printing</option>
<option value="maintenance">PC Maintenance</option>
<option value="internet">Internet Problem</option>
<option value="software">Software</option>
<option value="email">Email Problem</option>
<option value="usbcd">USB/CD Problem</option>
</select>
<select id="MemName" style="display: none">
<option value="blank">Choose</option>
<option value="john">John</option>
<option value="hen">Hen</option>
</select>
<select id="EmpName" style="display: none">
<option value="blank">Choose</option>
<option value="smith">Smith</option>
<option value="will">William</option>
<option value="Gor">George</option>
</select>
<input type="submit" value="Submit" class="button" />
</form>
<?php
if (isset($_POST['formsubmitted']))
{
$operationno = $_POST['ono'];
echo "<table id='tfhover' class='tftable' border='1' align='center'>";
echo "<tr align='center'><th></th><th align='center'>Type</th><th>Employee</th><th align='center'>Member</th><th align='center'>Operation No</th></tr>";
$query_retrieve_maintenance = "Select * from Maintenance where ID = '$operationno'";
$result_retrieve_maintenance = mysqli_query($dbh, $query_retrieve_maintenance);
while($row1 = mysqli_fetch_array($result_retrieve_maintenance))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MainType = $_POST['mt'];
$query_retrieve_by_type = "Select * from Maintenance where Type = '$MainType'";
$result_retrieve_by_type = mysqli_query($dbh, $query_retrieve_by_type);
while($row1 = mysqli_fetch_array($result_retrieve_by_type))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$MemName = $_POST['mn'];
$query_retrieve_by_member = "Select ID from Member where Name = '$MemName'";
$result_retrieve_by_member = mysqli_query($dbh, $query_retrieve_by_member);
$membID = mysqli_fetch_row($result_retrieve_by_member);
$memb_id = $membID[0];
$query_retrieve_by_membername = "Select * from Maintenance where MemberID = '$memb_id'";
$result_retrieve_by_membername = mysqli_query($dbh, $query_retrieve_by_membername);
while($row1 = mysqli_fetch_array($result_retrieve_by_membername))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$memb_id."</td> ";
echo "<td>".$row1['EmpName']."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
$EmpName = $_POST['me'];
$query_retrieve_by_employee = "Select ID from Employee where Name = '$EmpName'";
$result_retrieve_by_employee = mysqli_query($dbh, $query_retrieve_by_employee);
$emplID = mysqli_fetch_row($result_retrieve_by_employee);
$empl_id = $emplID[0];
$query_retrieve_by_emplid = "Select * from Maintenance where EmployeeID = '$empl_id'";
$result_retrieve_by_emplid = mysqli_query($dbh, $query_retrieve_by_emplid);
while($row1 = mysqli_fetch_array($result_retrieve_by_emplid))
{
echo "<tr>";
echo "<td><a href='PastOperationsDet.php?operation_number=".$row1['ID']."' target='_blank'>Show</a></td> ";
echo "<td>".$row1['Type']."</td> ";
echo "<td>".$row1['MemName']."</td> ";
echo "<td>".$empl_id."</td> ";
echo "<td>".$row1['ID']."</td> ";
}
echo "</table>";
}
?>
Nass,
I took the liberty to make a fiddle for this case.
Take a look at it and ask if you don't understand it.
i hope it helps.
Kind regards, Alex
In this link, http://jsfiddle.net/QthB6/10/, it's set up in a clean way, like;
function blockify () { // for style.display = "block"
}
function unblockify () { // for style.display = "none"
}
At first try to simplify your code
function check() {
var dropdown = document.getElementById("OpType");
var current_value = dropdown.options[dropdown.selectedIndex].value;
var aIds = ['operationno', 'MainType', 'MemName', 'EmpName'];
for(var i = aIds.length; i>=0; i-- ) {
var ob = document.getElementById(aIds[i]);
if( current_value == aIds[i] ) {
ob.style.display = "block"
}
else {
ob.style.display = "none"
}
}
....
<select id="OpType" onChange="check();">
<option value="blank">Choose</option>
<option value="operationno">Operation No</option>
<option value="MainType">Operation Type</option>
<option value="MemName">Maintenance Member</option>
<option value="EmpName">Employee</option>
</select>
....
Then append "name" atrtribute to your input's and select's field.
And then try to print_r your $_POST array to see it values.

Categories