I am trying to get user selection from php form but instead of name I am getting id of elements. instead of ids I want to get names. Please help
here is the url
http://efinancec.com/d/drop4/index.php
and here is the code
<form action="../form/form1.php" method="post" enctype="multipart/form-data">
<div class="frmDronpDown">
<div class="row">
<label>Training:</label><br/>
<select name="training" id="training-list" class="demoInputBox" onChange="getCourse(this.value);">
<option value="">Select Training</option>
<?php
foreach($results as $training) {
?>
<option value="<?php echo $training["id"]; ?>"><?php echo $training["training"]; ?></option>
<?php
}
?>
</select>
</div>
<div class="row">
<label>Course:</label><br/>
<select name="course" id="course-list" class="demoInputBox" onChange="getCountry(this.value);">
<option value="">Select Course</option>
</select>
</div>
<div class="row">
<label>Country:</label><br/>
<select name="country" id="country-list" class="demoInputBox" onChange="getCity(this.value);">
<option value="">Select Country</option>
</select>
</div>
<div class="row">
<label>City:</label><br/>
<select name="city" id="city-list" class="demoInputBox" onChange="getDates(this.value);">
<option value="">Select City</option>
</select>
</div>
<div class="row">
<label>Dates:</label><br/>
<select name="dates" id="dates-list" class="demoInputBox" onChange="getPrice(this.value);">
<option value="">Select Dates</option>
</select>
</div>
<div class="row">
<label>Online Onsite Price:</label><br/>
<select name="price" id="price-list" class="demoInputBox">
<option value="">Select Online or Onsite</option>
</select>
</div>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
and this is how I am getting the values from sql database
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_POST["training_id"])) {
$query ="SELECT * FROM course WHERE training_id = '" . $_POST["training_id"] . "'";
$results = $db_handle->runQuery($query);
?>
<option value="">Select Course</option>
<?php
foreach($results as $course) {
?>
<option value="<?php echo $course["id"]; ?>"><?php echo $course["course"]; ?></option>
<?php
}
}
?>
Change this line:
onChange="getCourse(this.value);">
To this :
onChange="getCourse(this.text);">
You are passing id of the course as the value of dropdown and calling that value which is fine but you need to call the text of select option to get the course name.
I changed this.value to this.text as suggested and created the new page and it stoped working at all now it is not pulling the records from database except the first one. Here is the link
http://efinancec.com/d/drop4/index1.php
where as my earlier page is still working fine.
http://efinancec.com/d/drop4/index.php
I think I could not convey my problem earlier. My depended dropdown is working fine but when a user submits the form in the email I receive the ids instead of name. Thats the problem.
For example I myself made some selections on index.php and submitted form Here is the email I got
training: 1
course : 101
country: 1001
city: 5005
Basically I am getting the the respective ids instead of name.
Related
I am developing web application for that i am using codeigniter-3 framework,i have one hardcoded dropdown in view file that is working fine as i expected.in my listing page one edit option is there i have passed the data from controller to the view file for binding the data for editing it's working fine except select dropdown can you please help me to fix the issue...?
<div class="form-group">
<label for="exampleInputName1">Movie Type</label>
<select name="m_type" id="" class="form-control">
<option value="">No Selected</option>
<option value="1">Horror</option>
<option value="2">Comedy</option>
<option value="3">Romance</option>
</select>
</div>
//it's working fine for Book Qty
<div class="form-group">
<label for="exampleInputName1">Book Quantity</label>
<input type="text" name="b_qty" class="form-control" value="<?php echo $res[0]->book_quantity; ?>" id="exampleInputName1" placeholder="">
</div>
dump
array(1) {
[0]=>
object(stdClass)#32 (13) {
["id"]=> '11'
["tank_type"]=> "1"
}
}
i want to bind the Horror in the edit page dropdown by default in this case.
Use selected attribute to do that or jQuery Code
jQuery('#m_type').val('1').trigger('change')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select name="m_type" id="m_type" class="form-control">
<option value="">No Selected</option>
<option value="1">Horror</option>
<option value="2">Comedy</option>
<option value="3">Romance</option>
</select>
<select class="form-control" id="customer_id" name="customer_id">
<?php foreach ( $array as $item ){ ?>
<option value="<?php echo $item->id ?>"<?php echo($item->id=='1')?'selected':''; ?>><?php echo $item->label; ?></option>
<?php }?>
</select>
I just start learn PHP, HTML thing, but got bumped in to select options and handling.
here is my code:
<select id="VarRole" class="form-control">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</Select>
<select id="VarAcct" class="form-control">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</Select>
if (isset($_POST['VarRole'] && $_POST['VarAcct'])) {
$_SESSION['VarAcct'] = $_POST['VarAcct'];
$_SESSION['VarRole'] = $_POST['VarRole'];
echo '<script type="text/javascript"> location.href = "success.php"; </script>';
}
My goal is to send 2 selected result to become session variables and if success it will redirect to success.php page.
Sorry if my explanation are not quite clear, feel free to ask.
Edit:
I try below solution but still fail to redirect to success.php page, im adding full page so i hope it can be clear. thank you so much guys!
content of P1.php
<?php
session_start();
if(!empty($_POST["add_record"])) {
if ( isset(
$_POST['VarAcct'],
$_POST['VarRole'])) {
$_SESSION['VarAcct'] = $_POST['VarAcct'];
$_SESSION['VarRole'] = $_POST['VarRole'];
ob_clean();
exit( header('location:P2.php'));
}
}
?>
<body>
<form class="form-group form-default" method="post">
<div class="form-group row">
<div class="col-sm-10">
<select name="VarRole" class="form-control">
<option value="1">1
<option value="2">2
<option value="3">3
</select>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<select name="VarAcct" class="form-control">
<option value="1">A
<option value="2">B
<option value="3">C
</select>
</div>
</div>
<input name="add_record" type="submit" value="Submit" class="btn btn-primary">
Back
</form>
</body>
this is the content of success.php
<?php
session_start();
$VarAcct = $_SESSION['VarAcct'];
$VarRole = $_SESSION['VarRole'];
echo $VarAcct;
echo $VarRole;
echo 'Back';
?>
Finally it works forgot to add session_start() thank you professor for this one!
Form elements do NOT send the ID attribute when the form is submitted - it is the name that forms the key in the request array.
<select name="VarRole" class="form-control">
<option value="1">1
<option value="2">2
<option value="3">3
</Select>
<select name="VarAcct" class="form-control">
<option value="1">A
<option value="2">B
<option value="3">C
</Select>
isset will accept multiple items to verify at once ( returns false if any item fails the test ) but you separate with a comma - there is no need to use && within the arguments.
One other thing - it would be cleaner to use header to redirect rather than use Javascript as you were trying to do.
<?php
if ( isset(
$_POST['VarRole'],
$_POST['VarAcct']
)) {
$_SESSION['VarAcct'] = $_POST['VarAcct'];
$_SESSION['VarRole'] = $_POST['VarRole'];
ob_clean();
exit( header('location: success.php'));
}
?>
I have the following code, I am trying to make it so that the selected field displays on a php page when I return that hit the submit button, I'm doing this below.
<form action="welcome.php" method="post">
<div class="form-group">
<select class="form-control" id="inputState" style="width: 100%">
<option selected>
Choose...
</option>
<option name="account" value="1">
Minecraft Account
</option>
<option name="cape" value="2">
Minecraft Cape
</option>
</select>
</div>
<input type="submit">
</form>
this is my php echo code, but it does not work
<?php echo $_POST["account"]; ?>
<?php echo $_POST["cape"]; ?>
Set name to your select control
<select name="inputState" class="form-control"
Then you can get the "value" of selected item
<?php echo $_POST["inputState"]; ?>
Here i have two fields such as follows
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
i will be using only one field at a time and the remaining field will be hidden and the problem am always getting the value A which is present in second select tag while getting submitted.how can i pass the correct value which i choosed
Here is the solution what ever field will be hidden add disabled in the input field Check the code below.
<?php
if(isset($_POST['abc_type'])){
echo $_POST['abc_type'];
}
?>
<form action="" method="post">
<div class="left_2 two">
<select name="abc_type" id="abc_type_2" class="form-control">
<option value="AB">LSK-AB</option>
<option value="AC">LSK-AC</option>
<option value="BC">LSK-BC</option>
</select>
</div>
<div class="left_2 one">
<select name="abc_type" id="abc_type_1" class="form-control">
<option value="A">LSK-A</option>
<option value="B">LSK-B</option>
<option value="C">LSK-C</option>
</select>
</div>
<input type="submit" name="submit" value="submit"/>
</form>
I'am looking for a hide show script based on parentCatId and catId!
This is the div i try to hide and or show! div class="item-post-lot-area"
<div class="item-post-lot-area">
<label for="s_lotsize">
<?php _e('Lot Area', 'ctg_housing'); ?>
</label>
<div class="row collapse prefix-radius">
<div class="item-post-area-sign columns">
<span class="prefix"><?php echo osc_get_preference('metric','ctg_housing_theme'); ?></span>
</div>
<div class="item-post-area-number columns">
<input type="number" name="s_lotsize" id="s_lotsize" value="<?php if(isset($housingOut['s_lotsize'])) { echo $housingOut['s_lotsize'];} ?>" >
</div>
</div>
</div>
what i try!
item-post-lot-area field will all time show when loading the page! And will hide when selected the following parentCatId and catId
<option value="28">Vacation</option>
<select id="catId" name="catId" class="valid">
<option value="28">Select Subcategory</option>
<option value="29">Pension House</option>
<option value="30">Inn / Motel</option>
<option value="31">Hotel & Resort</option>
</option>
</select>
<select id="catId" name="catId" class="valid">
<option value="32">Select Subcategory</option>
<option value="33">Space</option>
<option value="34">Office</option>
<option value="35">BPO</option>
<option value="36">Economic</option>
</select>
Can someone explain me how to do this?
Thanks
You're probably looking along the lines of using .on("change") to run when the select element is changed. You can then check which value (if need be) has been selected, and then use $(".item-post-lot-area").hide() to hide the div.
$("#catId").on("change", function(){
$(".item-post-lot-area").hide();
});