I have this php grid display from ms sql server.
<?php while ($record = sqlsrv_fetch_array($result1)) { ?>
<tr bgcolor="#db97c6">
<td nowrap="nowrap" align="center"><?php echo $record['ProductName']; ?></td>
<td nowrap="nowrap" align="center"><?php echo $record['BrandName']; ?></td>
<td nowrap="nowrap" align="center"><?php echo $record['ProductPrice']; ?></td>
<td nowrap="nowrap" align="center"><?php echo number_format($record['ProductQty'],0); ?></td>
<td nowrap="nowrap" align="center"><?php echo number_format($record['TotalValue'],2); ?></td>
<td nowrap="nowrap" align="center"><?php echo number_format($record['Discount'],2); ?></td>
<td nowrap="nowrap" align="center"><?php echo number_format($record['NetValue'],2); ?></td>
<td nowrap="nowrap" align="center"><?php echo number_format($record['QtySupplied'],0); ?></td>
<td align="center">
<img src="images/update.png" height="15" width="15">
</td>
</tr>
<?php
}
?>
I want to pass PurchaseOrderDetlID to a javascript function which will open a popup window to edit the selected record
this is the javascript function.
function openForm(ParamId) {
$MyPurchaseOrderDetlID = ParamId;
document.getElementById("popupForm").style.display="block";
}
this is the popup window
<div class="login-popup">
<div class="form-popup" id="popupForm">
<form action="ProfileSrc.php" class="form-container">
<input type="text" id="ParamId" name="ParamId" value = "<?php echo $MyPurchaseOrderDetlID;?>" style="width:60px" >
<br>
<label for="QtyIn"> <strong>Qty Supplied</strong></label>
<br><br>
<input type="number" id="QtyIn" name="QtyIn" value=0.00 style="width:60px; text-align: right" required>
<br><br>
<button type="submit" class="btn">Save</button>
<button type="button" class="btn cancel" onclick="closeForm()">Close</button>
</form>
</div>
</div>
I am unable to pass PurchaseOrderDetlID to the popup (edit) window
You can pass it through the js function parameter. The same way you change the style of the form (display = block), you can set the value of the input:
function openForm(ParamId) {
document.getElementById("popupForm").style.display = "block";
document.getElementById("ParamId").value = ParamId;
}
Also no need to add the value in the form using PHP:
<input type="text" id="ParamId" name="ParamId" value="" style="width:60px">
This way every time openForm gets called/triggered it will set the value of the input with the desired value.
Related
I have a form table, in which when I click on Show button, then a popup window open. Till now everything is good.
But after click on Show button, I also want to send php variable in popup window and want to show values related to that variable. How it can be possible?
My table is below
<table align="center">
<?php
include("connection.php");
$query1=mysql_query("select * from career") or die(mysql_error());
while($row1=mysql_fetch_array($query1))
{
extract($row1);
?>
<tr>
<td>Designation</td>
<td><input type="text" name="des" value="<?php echo $designation; ?>"></td>
</td>
</tr>
<tr>
<td>Number of position</td>
<td><input type="text" name="des" value="<?php echo $no_of_position; ?>"></td>
</td>
</tr>
<tr>
<td>Experience</td>
<td><input type="text" name="des" value="<?php echo $experience; ?>"></td>
</td>
</tr>
<tr>
<td>Qualification</td>
<td><input type="text" name="des" value="<?php echo $qualification; ?>"></td>
</td>
<tr>
<td>Job profile</td>
<td><input type="text" name="des" value="<?php echo $job_profile; ?>"></td>
</tr>
<tr>
<td><?php echo"$id"; ?></td>
<td><button onclick="document.getElementById('id01').style.display='block'" style="width:auto;" id="id1">Show</button>
</td>
</tr>
<tr>
<td></td>
<td> </td>
</tr>
<?php } ?>
</table>
In above code when I click on Show Button, then popup window open, code is below:
<div id="id01" class="modal1">
<form class="modal1-content animate" action="xyz.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close modal1">×</span>
</div>
<div class="container">
<div>Content</div>
</div>
</form>
</div>
<script>
// Get the modal1
var modal1 = document.getElementById('id01');
// When the user clicks anywhere outside of the modal1, close it
window.onclick = function(event) {
if (event.target == modal1) {
modal1.style.display = "none";
}
}
</script>
I want to send id variable, by which I can fetch values from database in popup window.
Thank you.
If I understand correctly you need an ajax call to a php page like this:
modalService.php
if(!isset($_GET['id']){
echo "no request";
exit;
}
$id = $_GET['id'];
//Do your query and echo the modal content
table
<td><?php echo $id; ?></td>
<td>
<button onclick="myFunction('<?php echo $id; ?>')" >Show</button>
</td>
JS
function myFunction(id){
var modal = document.getElementById("id01");
modal!==null && (modal.style.display="block");
var modalServiceUrl = "./modalService.php?id="+id;
//xhr to get modalService
}
EDIT: USING JQUERY
<button data-queryid="<?php echo $id; ?>" class="showModal">Show</button>
jQuery(document).ready(function($){
var modal = document.getElementById("id01");
$("button.showModal").on("click", function(){
modal.fadeIn();
var id = $(this).attr("data-queryid");
var modalServiceUrl = "./modalService.php?id="+id;
modal.load(modalServiceUrl);
});
});
i am making a simple quiz
the code below is my code for echoing the questions in the database
i used while loop to output the values in the database
i used the q_question for the name of each radio button, because if i put (sample : name="question" which is fixed, when it loop i am only available to pick 1 radio button even if theres 2 or more questions )
<?php
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $rows['q_question'] ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
</table></td>
</tr>
<hr>
</table><br>
<?php
}
?>
my problem is i cannot get the values of the radio button
im trying $my_answer=$_POST['$q_question'];(and i think this is so wrong) + submit button
help me get the values of the radio button, using php
but if you got idea using javascript etc.. im happy to see it
i have a problem when i passing variable value from FancyBox. First, i will tell the code :
Here is the code in the FancyBox :
JavaScript
function post_value(no){
parent.setSelectedUser(document.forms[no]["NO_INDUK"].value);
parent.$.fancybox.close();
}
html
while($baris = mysqli_fetch_assoc($hasil))
{
//1 item($baris);
$no++;
?>
<tr>
<form name="<?php echo $no ?>" method='post'>
<td><?php echo $no ?></td>
<td><input id="NO_INDUK" class="form-control" type="text" name="NO_INDUK" size="5" value="<?php echo $baris["NO_INDUK"] ?>" readonly/></td>
<td><?php echo $baris["NAMA_SISWA"] ?></td>
<td><?php echo $baris["NAMA_WALI"] ?></td>
<td><?php echo $baris["ALAMAT"] ?></td>
<td>
<a class="btn btn-success" href="#" onclick='post_value(<?php echo $no ?>)'> Pilih</a>
</td>
</form>
</tr>
<?php
} //untuk while
?>
Then this is source page view :
html source view
<tr>
<form name="2" method='post'>
<td>2</td>
<td><input id="NO_INDUK" class="form-control" type="text" name="NO_INDUK" size="5" value="112312" readonly/></td>
<td>Angga Lisdiyanto</td>
<td>asa</td>
<td>asdsad</td>
<td>
<a class="btn btn-success" href="#" onclick='post_value(2)'> Pilih</a>
</td>
</form>
</tr>
<tr>
<form name="3" method='post'>
<td>3</td>
<td><input id="NO_INDUK" class="form-control" type="text" name="NO_INDUK" size="5" value="2543" readonly/></td>
<td>Fina Arzika Humaidah</td>
<td>Nur Kojim</td>
<td>Campurejo, Panceng, Gresik</td>
<td>
<a class="btn btn-success" href="#" onclick='post_value(3)'> Pilih</a>
</td>
</form>
</tr>
Then when i click the button 'Pilih', the FancyBox won't close and the value is not passed. If the javascript code like this one, it can successfull passing a value :
function post_value(no){
parent.setSelectedUser(no); //just test, passing from no value
parent.$.fancybox.close();
}
After debugging it with Chrome, there are error in this line :
parent.setSelectedUser(document.forms[no]["NO_INDUK"].value);
And the error message is :
Uncaught TypeError: Cannot read property 'NO_INDUK' of undefined
That is, i hope there are any reply and i would be very happy if there are someone can help me out.
Thanks :)
SOLVED (with my blacked eyes!).
So as #JFK said, onclick='post_value(n)' is passing form index not the form's name. So i try it out with adding several char in the form's name like this :
<form name="form<?php echo $no ?>" method='post' action="">
Then in the button is like this one :
onclick='post_value("form<?php echo $no ?>")'
And on the JavaScript :
function post_value(NamaForm){
parent.setSelectedUser(document.forms[NamaForm]["NO_INDUK"].value);
parent.$.fancybox.close();
}
That is.
Sorry for Indonesian language may confuse you. :)
I have an HTML table. I need to get specific cell value if column is checked! For each row I have a checkBox.
<table id="tabellaOrdinaFarmaci" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Codice Farmaco</th>
<th>Nome Farmaco</th>
<th>Quantità </th>
<th>Quantità di alert</th>
<th>Stato</th>
<th>Quantità da ordinare</th>
<th></th>
</tr>
</thead>
</thead>
<tbody>
<?php
foreach ($query as $row):
$quantitaDaOrdinare = $row->alert - $row->quantita;
if ($quantitaDaOrdinare > 0) {
?>
<tr id="<?php echo $row->aic; ?>" >
<td ><?php echo $row->aic; ?></td>
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
<td><?php echo $row->quantita; ?></td>
<td><?php echo $row->alert; ?></td>
<td><?php echo $row->stato; ?></td>
<td>
<input type="text" class="form-control auto" name="codiceFarmaco" value="<?php echo $quantitaDaOrdinare ?>"/>
</td>
<td> <label>
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> ">
</label></td>
</tr>
<?php
} else {
}
endforeach;
?>
</tbody>
I need (using javascript or jquery) to get, if a button is clicked, every value of cell that have name="nomeFarmaco" for every row that is checked! I try to call this function whe
function getValue(){
var nome = $('input[name="checkBox"]:checked').map(function() {
return $(this).parent().parent().parent().find('name="nomeFarmaco').val();
}).get();
return nome;}
but nome is an empty array! any ideas? thanks in advance!
You can put a custom attribute for the check box and set the value in this attribute.
Like this :
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> " customattr="<?php echo $row->denominazione ?>">
And you javascript function will be :
function getValue(){
var nome = $('input[name="checkBox"]:checked').attr('customattr');
return nome;
}
I think this is typo?
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
Change it to:
<td name="nomeFarmaco"><?php echo $row->denominazione ?></td>
And you are targetting a <td> and .val() won't work. Should be .text()
var name = [];
$('input[name="checkBox"]').click(function(){
if($(this).is(':checked')) {
name.push($(this).parent().parent().siblings('td[name="nomeFarmaco"]').text());
} else {
var index = name.indexOf(name);
name.splice(index, 1);
}
console.log(name);
});
I want to sum table rows dynamically as the user inputs values. Since the number of rows can vary I want to use a php loop to accomplish this. I'm having problems getting the loop to work correctly. If, for example, there are two individual rows to sum only the bottom row will be summed.
<script type="text/javascript">
var sumScoreF = function(a) {
var rowtotal = 0;
n = new Array();
for (i = 1; i <= 3; i++) {
if (parseInt(document.getElementById(a + i).value) > 0) {
n[i] = parseInt(document.getElementById(a + i).value);
rowtotal += n[i];
}
}
document.getElementById(a + 'total').value = rowtotal;
};
</script>
The following is an example of a single row sum. The total column continues to be summed as values are entered. This is a nice effect but not necessary.
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<tr>
<td>
<input name="p1g1" id="p1g1" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1g2" id="p1g2" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1g3" id="p1g3" type="text" value="" onChange="sumScoreF('p1g')" />
</td>
<td>
<input name="p1gtotal" id="p1gtotal" type="text" value="" />
</td>
</tr>
</table>
Here is my attempt at looping additional rows using php and javascript. The first row will not sum but the second row will. I think the problem is with the javascript variable "m" in that it goes directly to the last row but I can't figure out how to fix it.
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<?php for($j=1;$j<=3;$j++) { ?>
<script type="text/javascript">
var k = <?php echo json_encode($j); ?>;
var m = 'p'+k+'g';
</script>
<tr>
<td>
<input name="<?php echo 'p'.$j.'g1'; ?>" id="<?php echo 'p'.$j.'g1'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g2'; ?>" id="<?php echo 'p'.$j.'g2'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g3'; ?>" id="<?php echo 'p'.$j.'g3'; ?>" type="text" onChange="sumScoreF('m')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'gtotal'; ?>" id="<?php echo 'p'.$j.'gtotal'; ?>" type="text" />
</td>
</tr>
<?php } ?>
Any help is greatly appreciated. Thanks.
Used PHP to echo the loop variable within the onChange javascript function call:
<table>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>total</td>
</tr>
<?php for($j=1;$j<=3;$j++) { ?>
<tr>
<td>
<input name="<?php echo 'p'.$j.'g1'; ?>" id="<?php echo 'p'.$j.'g1'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g2'; ?>" id="<?php echo 'p'.$j.'g2'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'g3'; ?>" id="<?php echo 'p'.$j.'g3'; ?>" type="text" onChange="sumScoreF('<?php echo 'p'.$j.'g'; ?>')" />
</td>
<td>
<input name="<?php echo 'p'.$j.'gtotal'; ?>" id="<?php echo 'p'.$j.'gtotal'; ?>" type="text" />
</td>
</tr>
<?php } ?>