i really need a quick answer for this.
how can i disable a select option once value has changed?
it must be available on firstload, then after the user tries to select it first time, it is the disabled for further change. so the user can choose a value only once.
HERE is my code which is dynamic?
<TABLE id="dataTable" width="350px" >
<TR>
<TD><INPUT type="checkbox" name="chk[]"/></TD>
<TD>
<select name="ItemNo[]" id="select" value="ItemNo" onChange="loadXMLDoc(this.value)">
<?php
$sql2="select * from jewelry_system.item where NumStored !='0' order by ItemName asc";
$result2 = mysql_query($sql2);
while($row2=mysql_fetch_array($result2)){
?>
<option value="<?php echo $row2['ItemNo']?>"> <?php echo $row2['ItemName'];?> Php:<?php echo $row2['SalePrice'];?> </option>
<?php } ?>
</select>
</TD>
</TR>
</TABLE >
what do i put in the javascript?
thanks in advance
This should do what you want if it's in your onChange event
this.disabled = true;
Without extending the loadXMLDoc method or adding another method to disable the field the cleanest method would probably be to append this.disabled = true to your select.onchange declaration
<select name="ItemNo[]" id="select" value="ItemNo" onChange="loadXMLDoc(this.value);this.disabled = true;">
Related
<div class="form-group"><label for="unit_of">Unit of Measure</label>
<select class="form-control-sm selectpicker" multiple="multiple" id="unit_of" name="unit_of[]" data-selected-text-format="count">
<?php $sql = "select * from unit_of";
$res = mysqli_query($db_handle, $sql);
while ($list = mysqli_fetch_assoc($res)) {
$unit_of = $list['unit_of'];
?>
<option><?= $unit_of; ?></option>
<?php
}
?>
</select>
</div>
<input type="text" class="form-control-sm" id="rates" name="rates" >
<input type="text" class="form-control-sm" id="rates1" name="rates1" style="display:none">
<input type="text" class="form-control-sm" id="rates2" name="rates2" style="display:none">
In the dropdown
Per Minute
Per Page,
Per Hour,
Per Day,
Per Month,
Per Item,
Per Contract,
Others
I want onchange multiple select hide and show input types number e.g.(name="per_page") e.g.("Enter Rate Per Page") for three input type
Thanks in Advance
If I understand correctly, there are 2 questions here really:
How to restrict a multiple select to a max of 3 selections?
There are multiple ways to achieve this, but my recommendation would be to validate this right before the form is submitted. If you're using a form validation library, try adding the code in there. If not, then you can add a custom submit event handler that will validate the selections. Maybe something like:
$("form").on("submit", function(e) {
var selectionCount = $("#unit_of option:selected").length;
if (selectionCount > 3) {
e.preventDefault();
alert("You may only select up to 3 options.");
}
});
How to add a placeholder to the multiple select?
You can add a placeholder option just before the PHP code adds the other options, like so:
<select class="form-control-sm selectpicker" multiple="multiple" id="unit_of"
name="unit_of[]" data-selected-text-format="count">
<option value="">Enter Rate Per Page</option>
<?php $sql = "select * from unit_of";
$res = mysqli_query($db_handle, $sql);
while ($list = mysqli_fetch_assoc($res)) {
$unit_of = $list['unit_of'];
?>
<option><?= $unit_of; ?></option>
<?php
}
?>
</select>
Of course, with this approach, you'll need to add extra validation code to make sure that the placeholder option is not one of the selected options.
Can't find posts/answers that work for me. Everything in my page and modal works fine. I'm able fill the form out and select items in my dropdown the way i want. Issue is when i submit the form the page returns error 500 and says it's not working. Any help would be greatly appreciated, new to coding.
Following is one of the html dropdown items (i have three in the form + 2 input fields. As input fields they all worked fine and the form worked perfectly until i converted three to dropdowns):
<tr>
<td>
<label class="col-form-label col-form-label-sm">Department</label>
</td>
<td width="10"></td>
<td>
<select type="text" name="proj_dept" class="form-control form-control-sm" id="validationDefault01" required>
<option value="" selected disabled>Select</option>
<?php $result3 = $dbConn->query("SELECT * FROM a0_lists WHERE list_group='Departments' ORDER BY list_code ASC");
while($row3 = $result3->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=".$row3['list_code'].">".$row3['list_code']."</option>";
} ?>
</select>
</td>
</tr>
Action php for form (again, this worked before I converted a couple fields to dropdowns:
`<?php require_once('../db.php');
$proj_name= $_POST['proj_name'];
$proj_desc= $_POST['proj_desc'];
$proj_priority= $_POST['proj_priority'];
$proj_status= $_POST['proj_status'];
$proj_dept= $_POST['proj_dept'];
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO a0_lists (proj_name, proj_desc, proj_priority, proj_status, proj_dept)
VALUES ('$proj_name', '$proj_desc', '$proj_priority', '$proj_status', '$proj_dept')";
$conn->exec($sql);
echo "<script>alert('Successfully Added!'); window.location='../proj/proj.php'</script>"; ?>`
I am trying to fetch values of drop-downs into a node-list having dynamically using a JavaScript. In this code all the drop down have created dynamically and entering the value in a single node-list array. But my query is how to use dynamically. Can anyone suggest me.
please help..
thanks for advance...
<?php
$j=1;
$proQuery=$this->db->query("select * from tbl_subcategory where category_id='$getInv->catg_id' and whr_to_use='for bom'");
foreach($proQuery->result() as $proRow){
?>
<tr>
<th style="width:200px"><?php $techQuery=$this->db->query("select * from tbl_technical_category where sub_catg_id='$proRow->subcategory_id'");
//echo $proRow->subcategory_id;
$i=1;
foreach($techQuery->result() as $techRow){//echo $techRow->techcategory_id;
?>
<select name="tech_prod" id="tech_prod<?=$j."^".$i;?>" class="form-control" required onchange="raptoit(this.id)" <?php if(#$_GET['view']!=''){ ?> disabled="disabled" <?php }?>>
<option value="" selected disabled><?php echo $techRow->tech_catg_name;?></option>
<?php $contQuery=$this->db->query("select * from tbl_technical_product where technical_sub_type='$techRow->techcategory_id'");
$k=1;
foreach($contQuery->result() as $contRow){
?>
<option value="<?php echo $contRow->technical_pro_id; ?>"><?php echo $contRow->tech_pro_name; ?></option>
<?php $k++;} ?>
</select><?php $i++;}?>
<input type="text" id="techId<?=$j;?>" name="techId[]" value="" readonly="" class="form-control">
</th>
</tr>
<?php $j++;}?>
<script>
function raptoit(d){
var zz=document.getElementById(d).id;
//alert(zz);
var myarra = zz.split("^");
var asx= myarra[1];
var asx11= myarra[0];
var value=asx11.split("tech_prod");
var mainId=value[1];
//alert(mainId);
// all select element.
var merge=document.getElementById(asx11+"^"+asx).value;
//alert(dropValue);
// convert nodeList to array
var nodesArray = [].slice.call(document.querySelector("select"));
//alert(nodesArray);
var result = nodesArray.map(select => {return select.value;}).join(',');
alert(result);
document.getElementById("techId"+mainId).value=result;
}
</script>
I have not looked in depth into your code but from a mere glance it seems you are doing it all wrong.
To get the items from the list and parse them on the server side. You should use ajax to communicate between the server and frontend. Look at this https://www.w3schools.com/php/php_ajax_php.asp
Here is my dilemma. A multi-select drop-down displays pre-selected options. When the user makes any changes, I'm running some code in the PHP action file (called through a submit button). I'm trying to accomplish this using a flag and updating the flag in the onchange event of "select option". The rest is working fine. I just wanted to execute the queries in action file only when the user changed selections in drop down rather than every time the form is submitted. However I'm unable to pass the flag successfully. I know I'm missing something basic and have spent two days looking at it. Any help is appreciated.
The relevant code is pasted below:
//Initialize flag
<?php
...
$multi_prog_change_flag = '0';
...
?>
//Hidden Form Element
<form action="update_u.php" method="post" id="cForm" name="cForm" onsubmit="return validateForm()" autocomplete="off">
...
<?php echo '<input type="hidden" id="email" value="'.$email.'"> ';?>
<?php echo '<input type="hidden" id="multiprogchangeflag" name="multiprogchangeflag" value="'.$multi_prog_change_flag.'"> ';?>
...
// Drop-down Element where update is triggered
<tr id="odd">
<td><select id="programName" name="programName[]" onchange="updateflag();>" multiple="multiple" size=10>
..
<option name="drop1" value ="<?php echo $data['Program_Id'] ?>" <?php if ($data[curr_prog] == '1') echo 'selected="selected"'; ?>> <?php echo $data['Program_Name'];?></option>
..
</select>
<input type="hidden" id="pNames" name="pNames" value="" />
</td>
</tr>
// Function to update flag
function updateflag() {
<document.getElementById("multiprogchangeflag").value = "1";
}
// update_u.php PHP Action File
$multi_prog_flag=mysql_real_escape_string($_POST['multiprogchangeflag']);
if ($multi_prog_flag == '1'){
$multi_prog_delete_query=mysql_query("UPDATE multi_prog_access SET is_act = '0', Updated_by = '$updatedby', update_timestamp = NOW() WHERE user_id = '$useid'");
$count = count($multi_prog_names);
for($i=0;$i<$count;$i++){
$multi_prog_ID=$multi_prog_names[$i];
$multi_prog_update_query=mysql_query("INSERT INTO multi_prog_access (user_id, Prog_id, created_by, is_act, Update_timestamp) VALUES ('$ids','$multi_prog_ID', '$updatedby', '1', NOW())");
}
}
You know when you are entering your personal information on a form, and you get to the state drop down box, most of the time you can type I and it will go right to the states that begin with I.
I am wanting to do the same thing here. My drop down box displays a list of options for a user to choose from. If they want to choose an option that starts with B I would like them to be able to type B and it will bring up the first option that starts with a B hopefully this is clear.
Here is the code
$sql = "SELECT iro_option, iro_desc from incrateopt
WHERE iro_div = ".$divnmbr."
AND iro_option NOT IN (
SELECT cm_optnum
FROM cmopt
WHERE cm_serialno = '".$serialno."'
)
AND CHAR_LENGTH(iro_desc) > 0
ORDER BY iro_desc ASC";
$result=$link->query($sql);
echo $link->error;
$ct = 1;
while($r=$result->fetch_array()):
$opnum = $r["iro_option"];
$opdesc = $r["iro_desc"];
$opdata[$ct] = $opnum." ".$opdesc;
$ct++;
endwhile;
$usearray = "opdata";
?>
<div style="font-weight: heavy;">
<tr>
<td>
<select name="Oparr" multiple size=7 valign=top STYLE="width: 500px;" <? echo $Oparr; ?>>
<?
foreach ($$usearray as $value):
echo "<option value='".$value."'>".$value."</option>\n";
endforeach;
?>
</select>
</td>
</tr>
I would imagine that you would do it in the select name some kinda of onkeypress function.
THANKS STACK!