I have three drop down list and few text input,the first drop down is using to hide some input there are no need to show and the second drop down is using to reload the page and make the third drop down take the info from database base on the option in second drop down.Now I face a problem with when I click the second drop down,the page reload,and the input hide in drop down 1 show again....
code to get value after reload:
<?php
#$utm=$_GET['utm']; // Use this line or below line if register_global is off
if(strlen($utm) > 0 and !is_numeric($utm))
{ // to check if $utm is numeric data or not.
echo "Data Error";
exit;
}
#$gpotp=$_GET['gpotp'];
if(strlen($gpotp) > 0 and !is_numeric($gpotp))
{
echo "Data Error";
exit;
}
?>
javascript to hide content(call by drop down 1):
<script>
function jsFunction(value)
{
var p = document.getElementById('ps');
var r = document.getElementById('rps');
var u = document.getElementById('upoint');
var m = document.getElementById('umng');
var t = document.getElementById('tmpass');
if ((value) == '1')
{
p.style.display = '';
r.style.display = '';
u.style.display = 'none';
m.style.display = 'none';
t.style.display = 'none';
}
else if ((value) == '2')
{
p.style.display = 'none';
r.style.display = 'none';
u.style.display = '';
m.style.display = 'none';
t.style.display = '';
}
if ((value) == '3')
{
p.style.display = 'none';
r.style.display = 'none';
u.style.display = '';
m.style.display = '';
t.style.display = '';
}
}
</script>
code to reload page(call when drop down 2):
function reload(form)
{
var val=form.utm.options[form.utm.options.selectedIndex].value;
var va2=form.gpotp.options[form.gpotp.options.selectedIndex].value;
self.location='CrtGroup.php?utm=' + val +'&gpotp=' + va2 ;
}
drop down 1:
<select name='gpotp' class='form-control' onmousedown=\"this.value='';\" onchange=\"jsFunction(this.value);\">
<option disabled selected value> -- select an option -- </option>";
if($stmt = $conn->query("$query3"))
{
while ($row2 = $stmt->fetch_assoc())
{
if($row2['Group_ID']==#$gpotp){echo "<option selected value='$row2[Group_ID]'>$row2[Group_Cat]</option>";}
else{echo "<option value='$row2[Group_ID]'>$row2[Group_Cat]</option>";}
}
}else
{
echo $conn->error;
}
echo"</select>
drop down 2:
echo"<select class='form-control' onchange=\"reload(this.form)\" name='utm' onmousedown=\"this.value='';\">";
echo"<option disabled selected value> -- select an option -- </option>";
if($stmt = $conn->query("$query2"))
{
while ($row2 = $stmt->fetch_assoc())
{
if($row2['Group_ID']==#$utm){echo "<option selected value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";}
else{echo "<option value='$row2[Group_ID]'>$row2[Tm_GroupID]</option>";}
}
}else
{
echo $conn->error;
}
echo"</select>";
drop down 3:
echo"<select class='form-control' name='umn' >";
echo"<option disabled selected value> -- select an option -- </option>";
if(isset($utm) and strlen($utm) > 0){
if($stmt = $conn->prepare("SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup where Tm_GroupID=? order by Mng_GroupID"))
{
$stmt->bind_param('i',$utm);
$stmt->execute();
$result = $stmt->get_result();
while ($row1 = $result->fetch_assoc()) {
echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>";
}
}else{
echo $conn->error;
}
/////////
}else{
///////
$query="SELECT DISTINCT Mng_GroupID,Group_ID,Tm_GroupID FROM mnggroup order by Mng_GroupID";
if($stmt = $conn->query("$query")){
while ($row1 = $stmt->fetch_assoc()) {
echo "<option value='$row1[Group_ID]'>$row1[Mng_GroupID]</option>";
}
}else{
echo $conn->error;
}
}
echo"</select>";
You could use window.name to store a flag that persists after the reload.
No links, excuse me, but you could use it instead of local-storage or cookies for simply implementing a logic to hide what you want after the page reloading. Es.:
if (window.name === "hide") {
element.style.display = "none";
}
Related
i hope this is the correct place to ask this. I'm working with a Wordpress theme which detects opening times of a business from a custom field, compares it to the current day and time and then displays a message to say if the business is currently open. This works perfectly in English, but when i change the site language to Spanish using qTranslate X Plugin, the business permanently appears as not open. I really have limited skills at this kinda thing, so i'm hoping someone can advise me.
From what i can see this is the js that does the comparison.
<?php
/* ============== Check TIme ============ */
if (!function_exists('listingpro_check_time')) {
function listingpro_check_time($postid,$status = false) {
$output='';
$buisness_hours = listing_get_metabox_by_ID('business_hours', $postid);
if(!empty($buisness_hours)){
if(!empty($postid)){
$lat = listing_get_metabox_by_ID('latitude',$postid);
$long = listing_get_metabox_by_ID('longitude',$postid);
}
//$timezone = getClosestTimezone($lat, $long);
$timezone = get_option('gmt_offset');
$time = gmdate("H:i", time() + 3600*($timezone+date("I")));
$day = gmdate("l");
$time = strtotime($time);
$lang = get_locale();
setlocale(LC_ALL, $lang.'.utf-8');
$day = strftime("%A");
$day = ucfirst($day);
foreach($buisness_hours as $key=>$value){
if($day == $key){
$dayName = esc_html__('Today','listingpro');
}else{
$dayName = $key;
}
$open = $value['open'];
$open = str_replace(' ', '', $open);
$close = $value['close'];
$close = str_replace(' ', '', $close);
$open = strtotime($open);
$close = strtotime($close);
$newTimeOpen = date('h:i A', $open);
$newTimeClose = date('h:i A', $close);
if($day == $key){
if($time > $open && $time < $close){
if($status == false){
$output = '<span class="grid-opened">'.esc_html__('Open Now~','listingpro').'</span>';
}else{
$output = 'open';
}
}else{
if($status == false){
$output = '<span class="grid-closed">'.esc_html__('Closed Now!','listingpro').'</span>';
}else{
$output = 'close';
}
}
}
}
}else{
if($status == true){
$output = 'open';
}
}
return $output;
}
}
Any direction would be greatly appreciated.
Here when I click post button it inserts a random value on database.
If a value already exists on database then show error. It works fine.
But I want to add 2/3 characters at the end of value if it already exists on database. If $check == 1 then I want to add some characters at the end of the value instead of showing alert. How to do this?
<?php
$con = mysqli_connect("localhost","root","","post") or die("unable to connect to internet");
if(isset($_POST['submit']))
{
$slug = $_POST['rand'];
$get_slug = "select * from slug where post_slug='$slug' ";
$run_slug = mysqli_query($con,$get_slug );
$check = mysqli_num_rows($run_slug );
// if $check==1 then i want to add 2 characters at the end of $slug .
if($check == 1)
{
// instead of showing alert i want to add 2 more characters at the end of that value and and insert it on database
echo "<script> alert('something is wrong') </script> ";
exit ();
}
else
{
$insert ="insert into slug (post_slug) values ('$slug') ";
$run = mysqli_query($con,$insert);
if($run)
{
echo "<p style='float:right;'> Posted successfully </p>";
}
}
}
?>
<form method="POST" >
<?php
$result = "";
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$chararray = str_split($chars);
for($i = 0; $i < 7 ; $i++)
{
$randitem = array_rand($chararray);
$result .= "".$chararray[$randitem];
}
echo $result ;
?>
<input type="hidden" value="<?php echo $result;?>" name="rand" />
<span class="input-group-btn">
<button class="btn btn-info" type="submit" name="submit">POST</button>
</span>
</form>
just run update query if $check == 1
if($check == 1){
$newSlug = $slug."xy";
$update = "update slug set post_slug = '".$newSlug."' where post_slug = '".$slug."'";
$run = mysqli_query($con,$update );
echo "<script> alert('Updated Successfully') </script> ";
exit ();
}
This is helpful for you
<?php
$con = mysqli_connect("localhost","root","","post" ) or die
( "unable to connect to internet");
if(isset($_POST['submit'])){
$tmp_slug = $_POST['rand'];
$slug = $_POST['rand'];
while(check_exiest($tmp_slug))
{
$tmp_rand = rand(11,99);
$tmp_slug = $slug.$tmp_rand;
}
$insert ="insert into slug (post_slug) values ('$tmp_slug') ";
$run = mysqli_query($con,$insert);
if($run)
{
echo "<p style='float:right;'> Posted successfully </p>";
}
}
public function check_exiest($slug)
{
$get_slug = "select * from slug where post_slug='$slug' ";
$run_slug = mysqli_query($con,$get_slug );
$check = mysqli_num_rows($run_slug );
if($check >= 1)
{
return true;
}
else
{
return false;
}
}
?>
Just few modification in your code to insert new value.
<?php
$con = mysqli_connect("localhost","root","","post") or die("unable to connect to internet");
if(isset($_POST['submit']))
{
$slug = $_POST['rand'];
$get_slug = "select * from slug where post_slug='$slug' ";
$run_slug = mysqli_query($con,$get_slug );
$check = mysqli_num_rows($run_slug );
if($check == 1)
{
$slug_new = $slug.'ab'; // Add 2 characters at the end
$update ="UPDATE slug SET post_slug = '$slug_new' WHERE post_slug = '$slug'";
$run = mysqli_query($con,$update);
}
else
{
$insert ="insert into slug (post_slug) values ('$slug') ";
$run = mysqli_query($con,$insert);
if($run)
{
echo "<p style='float:right;'> Posted successfully </p>";
}
}
}
?>
in the model alert is not working. if condition is working,the only problem with the alert box, its not showing the dialog box.Please help..
public function setJumlahPenumpang ($idJadwal,$idPemesanan,$jml,$booked,$selected){
$data1 = $this->db->query('select p.jumlah_kursi, j.jumlah_penumpang, p.harga from tb_po p JOIN tb_jadwal j ON j.id_po = p.id_bus WHERE j.id_jadwal ='. $idJadwal);
foreach ($data1->result_array() as $dataa1) {
$tersedia = $dataa1['jumlah_kursi'] - $dataa1['jumlah_penumpang'];
if($tersedia < $jml){
?>
<script type="text/javascript">
document.location = '<?php echo base_url(); ?>proses/cekKode1/<?php echo $idPemesanan ?>';
alert("Tidak ada Bus Beroperasi");
</script>
<?php
}else{
$data3 = $dataa1['harga'] * $jml;
$this->db->query('update tb_pemesanan set harga = '.$data3.' where id_pemesanan = '.$idPemesanan);
$data = $this->db->query('select jumlah_penumpang from tb_jadwal where id_jadwal ='. $idJadwal);
$this->db->query("update tb_jadwal set booked = '".$booked."' where id_jadwal = ".$idJadwal);
$this->db->query("update tb_pemesanan set kursi = '".$selected."' where id_pemesanan = ".$idPemesanan);
foreach ($data->result_array() as $dataa) {
$data2 = $dataa['jumlah_penumpang'] + $jml;
$this->db->query('update tb_jadwal set jumlah_penumpang = '.$data2.' where id_jadwal = '.$idJadwal);
}
}
}
}
Try Echo Before Script Tag I hope So it 'll work....
if($package_id == NULL) {
echo '<script type="text/javascript">
window.location.href = "'.base_url().'"
</script>';
return;
die();
}
I have a question about drilldown combo boxes using php and javascript.
When I choose parent data, child data become selectable; and it is controlled in javascript.
I tried to keep the two values after post, but the following code remain only the parent data. How do I remain the two values in drilldown combo boxes after submission?
HTML&php
<select id="SEL1" name="SEL1">
<option value="">---</option>
<?php
foreach ($parent_list as $parent => $children_list) {
echo '<option value="'.$parent.'"';
if ($parent == $_GET['SEL1']){
echo 'selected';
}
echo '>'.$parent.'</option>';
}
?>
</select>
<select id="SEL2" name="SEL2">
<option value="">---</option>
<?php
foreach ($parent_list as $parent => $children_list) {
echo '<optgroup label="'.$parent.'">';
foreach ($children_list as $children => $grandson_list) {
$view_children = str_replace($parent,"",$children);
echo '<option value="'.$children.'"';
if ($children == $_GET['SEL2']){
echo 'selected';
}
echo '>'.$view_children.'</option>';
}
echo '</optgroup>';
}
?>
</select>
javascript
function ConnectedSelect(selIdList){
for(var i=0;selIdList[i];i++) {
var CS = new Object();
var obj = document.getElementById(selIdList[i]);
if(i){
CS.node=document.createElement('select');
var GR = obj.getElementsByTagName('optgroup');
while(GR[0]) {
CS.node.appendChild(GR[0].cloneNode(true));
obj.removeChild(GR[0]);
}
obj.disabled = true;
}
if(selIdList[i+1]) {
CS.nextSelect = document.getElementById(selIdList[i+1]);
obj.onchange = function(){ConnectedSelectEnabledSelect(this)};
} else {
CS.nextSelect = false;
}
obj.ConnectedSelect = CS;
}
}
function ConnectedSelectEnabledSelect(oSel){
var oVal = oSel.options[oSel.selectedIndex].value;
if(oVal) {
while(oSel.ConnectedSelect.nextSelect.options[1])oSel.ConnectedSelect.nextSelect.remove(1);
var eF = false;
for(var OG=oSel.ConnectedSelect.nextSelect.ConnectedSelect.node.firstChild;OG;OG=OG.nextSibling) {
if(OG.label == oVal) {
eF = true;
for(var OP=OG.firstChild;OP;OP=OP.nextSibling)
oSel.ConnectedSelect.nextSelect.appendChild(OP.cloneNode(true));
break;
}
}
oSel.ConnectedSelect.nextSelect.disabled = !eF;
} else {
oSel.ConnectedSelect.nextSelect.selectedIndex = 0;
oSel.ConnectedSelect.nextSelect.disabled = true;
}
if(oSel.ConnectedSelect.nextSelect.onchange)oSel.ConnectedSelect.nextSelect.onchange();
}
ConnectedSelect(['SEL1','SEL2']);
//-->
</script>
I can't get this to work. I need to update the value of a column of the checked checkboxes in mysql. When I click the button it is supposed to update the value of the checked checkboxes. Here is my code for editLayout.php:
<form action="updateLayout.php" method="POST">
<input name="update" type="SUBMIT" value="Update" id="update">
<?php
$x = 'seats';
$linkID = # mysql_connect("localhost", "root", "Newpass123#") or die("Could not connect to MySQL server");
# mysql_select_db("seatmapping") or die("Could not select database");
/* Create and execute query. */
$query = "SELECT * from $x order by rowId, columnId desc";
$result = mysql_query($query);
$prevRowId = null;
$seatColor = null;
$tableRow = false;
//echo $result;
echo "<table class='map'>";
while (list($rowId, $columnId, $status, $name, $seatid) = mysql_fetch_row($result))
{
if ($prevRowId != $rowId) {
if ($rowId != 'A') {
echo "</tr></table></td>";
echo "\n</tr>";
}
$prevRowId = $rowId;
echo "\n<tr><td align='center'><table><tr>";
} else {
$tableRow = false;
}
if ($status == 0) {
$seatColor = "#A6E22E";
}
else if ($status == 1){
$seatColor = "#D34836";
}
else if ($status == 2){
$seatColor = "#00A0D1";
}
echo "\n<td bgcolor='$seatColor'>";
echo $seatid;
echo "<input type='checkbox' name='seats[]' id='seats' value=".$seatid."> </checkbox>";
echo "</td>";
}
echo "</tr></table></td>";
echo "</tr>";
echo "</form>";
echo "</table>";
/* Close connection to database server. */
mysql_close();
?>
And here is my code for the jquery residing on different page (functions.js). I already included this in the header:
jQuery(function($) {
$("form input[id='update']").click(function() {
var count_checked = $("[name='seats[]']:checked").length;
if(count_checked == 0) {
alert("Please select product(s) to update.");
return false;
}
if(count_checked == 1) {
return confirm("Are you sure you want to update these product?");
} else {
return confirm("Are you sure you want to update these products?");
}
});
});
And here is my updateLayout.php.:
<?php
$db = mysql_connect("localhost", "root", "Newpass123#");
if(!$db) { echo mysql_error(); }
$select_db = mysql_select_db("seatmapping");
if(!$select_db) { echo mysql_error(); }
if(isset($_POST['update'])) {
$id_array = $_POST['seats'];
$id_count = count($_POST['seats']);
for($i=0; $i < $id_count; $i++) {
$id = $id_array[$i];
$query = mysql_query("Update `seats` set `status`='2' where `seatid`='$seatid'");
if(!$query) { die(mysql_error()); }
}
header("Location: editLayout.php");
}
?>
I'm using jquery 1.11.0. I know there's a lot of sql injection in here and im still using mysql but I plan to change it all once I get this to work. Any kind of help is appreciated.
Thanks in advance.
Your update query doesn't use the correct update value. You use '$seatid', which isn't declared anywhere. You should use '$id'.
Change
for($i=0; $i < $id_count; $i++) {
$id = $id_array[$i];
$query = mysql_query("Update `seats` set `status`='2' where `seatid`='$seatid'");
if(!$query) { die(mysql_error()); }
}
into
for($i=0; $i < $id_count; $i++) {
$id = $id_array[$i];
$query = mysql_query("Update `seats` set `status`='2' where `seatid`='$id'");
if(!$query) { die(mysql_error()); }
}