So when i press submit every other field with input is printed, but selected option tag isnt printed in html, since option values are stored in an array..
select forms :
<div class="form-group">
<select class="form-control" name="from">
<option selected disabled>--Isvykimo vieta</option>
<?php foreach($cities as $city):?>
<option value='' style="color:black;"><?=$city;?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<select class="form-control" name="destination">
<option selected disabled>--Keliones tikslas</option>
<?php foreach($destinations as $destination):?>
<option value='' style="color:black;"><?=$destination;?></option>
<?php endforeach;?>
</select>
</div>
and when i try to post
<div class="ticket">
<?php if(isset($_POST['send'])) ?>
<div class="ticketInfo">
<h5><?php echo htmlentities($_POST['names']);?> <?php echo htmlentities($_POST['lastName']);?></h5>
<p>From: <?= $_POST['from'];?> To:<?= $_POST['destination'];?></p>
</div>
</div>
from to is just left blank
<option value="<?=$city;?>" style="color:black;"><?=$city;?></option>
your value of input was empty, try like this please
Related
I Have this form,but whenever the form_validation return FALSE. The Dropdown form always set to default which was PLEASE SELECT.
How do i Set the value like the input form,i dont know where to put the set_value
Dropdown Form:
<div class="form-group">
<select class="form-control form-control-sm" id="exampleFormControlSelect1" name="jenisKelamin">
<option value="">PLEASE SELECT</option>
<?php foreach ($system as $d) : ?>
<?php if ($d->system_type=="JENIS_KELAMIN"): ?>
<option value="<?= $d->system_value_txt ?>"><?= $d->system_value_txt ?></option>
<?php endif ?>
<?php endforeach; ?>
</select>
<small class="text-danger"><?= form_error('jenisKelamin') ?></small>
</div>
To set a default dropdown menu, you could use the set_select() method on your option input like this :
<div class="form-group">
<select class="form-control form-control-sm" id="exampleFormControlSelect1" name="jenisKelamin">
<option value="">PLEASE SELECT</option>
<?php foreach ($system as $d) : ?>
<?php if ($d->system_type=="JENIS_KELAMIN"): ?>
<option value="<?= $d->system_value_txt ?>" <?php echo set_select('jenisKelamin', $d->system_value_txt); ?> ><?= $d->system_value_txt ?></option>
<?php endif ?>
<?php endforeach; ?>
</select>
<small class="text-danger"><?= form_error('jenisKelamin') ?></small>
</div>
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"]; ?>
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.
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();
});
I have a page that selects value from different tables, when I select a class corresponding divisions are displayed (I used javascript) but when I click the view button I want all the values selected to be displayed. I am done with all the value including class, but corresponding division doesnot get displayed. since I am not much eficient in php, cant find out how, plz do help.
Here is my code that displays class in the textbox when selected.
<div class="field">
Class:
<div id="combo" style="width:20px;">
<select name="class" id="class" onChange="getDivision(this.value)">
<option value="">Select</option>
<?php
$select3="select * from ".TABLE_CLASS."";
$res=mysql_query($select3);
while($row=mysql_fetch_array($res)) {
?>
<option value="<?php echo $row['ID']?>" <?php if($row['ID']==#$_POST['class']){ ?> selected="selected"<?php }?>><?php echo $row['class'];?></option>
<?php
}
?>
</select>
</div>
</div>
<!--<div id="aa"></div>-->
<div class="field">
Division:
<div id="combo" style="width:20px;">
<select name="division" id="division" >
<!--<option value="">Select</option>-->
<option value="<?php echo $row['division'];?>"></option>
</select>
</div>
<!--<input type="text" name="a" id="a">-->
</div>
</div> <!-- /login-fields -->
<option value="<?php echo $row['division'];?>"></option>
You got nothing in those line between option tag. Put some thing there i am using $row['division']. just to show you that you are missing that
<option value="<?php echo $row['division'];?>"><?php echo $row['division'];?></option>