Select Value In Dropdown Dynamically Change Value In Textbox
I am working on this form where it has drop down and text box. When value selected in one drop-down should change value in text-box dynamically. for eg if I select a value '3' in
Solution 1:
Try this one:
<!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8" /><title>Untitled Document</title><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><scripttype="text/javascript">
$(document).ready(function(){
$('#empID').change(function(){
$.get('getEmpInfo.php',{empId:$(this).val()},function(data){
$('#emp_id').val(data);
});
});
});
</script></head><body><selectname="empID"id="empID"><optionvalue="">Select Emp</option><optionvalue='1'>Emp1</option><optionvalue='2'>Emp2</option><optionvalue='3'>Emp3</option><optionvalue='4'>Emp4</option></select><inputtype="text"name="emp_id"id="emp_id" /></body></html>
AT getEmpInfo.php PAge
<?phpif(isset($_REQUEST['empId'])){
// connection should be on this page $sql = mysql_query("select ename from emp where eid =".$_REQUEST['empId']);
$res = mysql_fetch_assoc($sql);
echo$res['ename'];die;
}
?>
Solution 2:
Try this,
$(document).ready(function() {
$("#name option").filter(function() {
return $(this).val() == $("#firstname").val();
}).attr('selected', true);
$("#name").live("change", function() {
$("#firstname").val($(this).find("option:selected").attr("value"));
});
});
My Be Duplicate : Duplicate
Solution 3:
For this solutions you can try:
//set textbox value change dynamic after dropbox had changed.
$('#' + yourDropBoxId).change(function ()
{
var dropDownValue = $('#'+ yourId).val();
// set new value for textbox
$('#' + yourTextBoxId).val(dropDownValue);
});
Solution 4:
Try this code which contains two textboxes :
<!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8" /><title>Untitled Document</title><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><scripttype="text/javascript"> $(document).ready(function(){ $('#empID').change(function(){ $.get('1.php',{empId:$(this).val()},function(data){ $('#emp_id').val(data);});});});</script><scripttype="text/javascript"> $(document).ready(function(){ $('#d1').change(function(){ $.get('1.php',{d1:$(this).val()},function(data){ $('#t1').val(data);});});});</script></head><body><?php$bdd = mysqli_connect('127.0.0.1', 'root', '', 'member');
$r= mysqli_query($bdd, "select * from info");
?><br>تشكيلة مباراة :<selectname="empID"id="empID"><optionvalue="">Select name from List...</option><?phpwhile ($d=mysqli_fetch_assoc($r))
{
?><optionvalue="<?=$d["prenom"];?><?=$d["nom"];?>"><?=$d["prenom"];?><?=$d["nom"];?></option><?php
}
?></select><inputtype="text"name="emp_id"id="emp_id" /><br><hr><br>تشكيلة مباراة :<selectname="d1"id="d1"><optionvalue="">Select name from List...</option><?php$r1= mysqli_query($bdd, "select * from info");
while ($d1=mysqli_fetch_assoc($r1))
{
?><optionvalue="<?=$d1["prenom"];?><?=$d1["nom"];?>"><?=$d1["prenom"];?><?=$d1["nom"];?></option><?php
}
?></select><inputtype="text"name="t1"id="t1" /></body></html>
PHP page :"1.php"
<?phpif(isset($_REQUEST['empId'])){ echo$_REQUEST['empId']; }
if(isset($_REQUEST['d1'])){ echo$_REQUEST['d1']; }
?>
Post a Comment for "Select Value In Dropdown Dynamically Change Value In Textbox"