How to display option values in ng-bind? - php

I want to display selected name from dropdown. i can see their names
like abc, xyz in dropdown but when i choose particular to display on
form. its candidate_id is printing on Form .
i want to print that name
only not id of name. i put candidate_id in value because i want to
store id in db after submitting form.
<select ng-model="empInfo.candidate_name" class="span2">
<option ng-repeat="x in names4" value="{{x.candidate_id}}">
{{x.candidate_name}}
</option>
</select>

If I understand it correctly, for display purpose you want the name and id for DB purposes.
Change in HTML markup :
<select ng-model="empInfo"
ng-options="emp.candidate_name for emp in names4"></select>
<div>id is : {{empInfo.candidate_id}}</div>
<div>name is : {{empInfo.candidate_name}}</div>
https://plnkr.co/edit/cOKY3GJIOsWWEqurmlEr?p=preview

Change the value attribute of option tag to x.candidate_name.

Change your valueto :
<select ng-model="empInfo.candidate_name" class="span2">
<option ng-repeat="x in names4" value="{{x.candidate_name}}">{{x.candidate_name}}</option>
</select>

<select ng-model="empInfo.candidate_name" class="span2">
<option ng-repeat="x in names4" value="{{x}}">{{x.candidate_name}}</option>
</select>{{x}} {{x.candidate_id}}{{x.candidate_name}}
While send just take id

Related

HTML option selects first default value instead of choosen value

Whenever I Select any other options in my drop down I am still getting the first value which is '?' instead of any of the other ones I picked.
<select name="role" class="form-control">
<option value="?" label ="Please Select a Role" id="role">Select a Role</option>
<?PHP foreach($roles as $role){ ?>
<option value= "<?=$role['id']?>" label=" <?=$role['role']?>"><?=$role['role']?>
</option>
<?PHP } ?>
</select>
What am I missing?
I made a mistake
The reason I was not getting getting any other values was because I was getting the ID of the first option so it would retrieve the same value each time
I solved it by moving the value of Id to the first select tag
My best guess is that you are pulling the value off whatever DOM element has an id of role. In this case, you've defined an option that always has the id role.

As I get the value of an option of a select ? symfony2

I have something like this in my view:
<form .....>
<select>
<option value="five">5</option>
<option value="ten">10</option>
<option value="fifteen">15</option>
</select>
</form>
As I do in the controller to take the values ​​of the options?
PD: It is a manual select , do not use types that actually genre with jquery .
You need to give your select a name, so it will be submitted in the form.
<select name="whatever">
Then in PHP, it will be in
$_POST['whatever'];

codeigniter: how to edit a "value" form the data that existed at the html <select> tag bootstrap

I have an edit form like this
<label class="col-md-4 control-label" for="textinput">Drainase</label>
<div class="col-md-7">
<select name="drainase" class="form-control">
<option value="" selected disabled style='display:none;'>Pilih Keadaan Drainase Lahan</option>
<option value="3">Bagus; Cukup Bagus</option>
<option value="2">Berlebihan; Buruk</option>
<option value="1">Sangat Berlebihan; Sangat Buruk; Tergenang</option>
</select>
</div>
then I have a syntax that contains the value to be edited like this
syntax a
<?php echo form_input('drainase', $hasil->drainase); ?>
the syntax a has a value get from the database. we assume syntax a contains the value 3. My problem here is how to keep value of 3 is entered in the edit form "drainase" and then in the form of "drainase", field automatically displays the selection of "Bagus; Cukup Bagus" because the value of syntax a has the value 3?
You probably want form_dropdown() instead of form_input(), it will generate SELECT form element.
The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected
Check documentation
U should use form_drop down() instead of form_input().

post value one dropdown to other dropdown using php mysql

include('connection.php');
$con=mysql_query("select * from province"); ?>
<select name="pid" style="float:left; width:135px;">
<option value="">Select Country</option>
<?php while($row=mysql_fetch_array($con)) {
$pid=$row['province_id'];
?>
<option value="<?=$pid?>" ><?php echo $row['province_name'] ?>
</option>
<?php } ?>
</select> -
<?php
$pid=$_POST['$pid'];
include('connection.php');
$con=mysql_query("select * from city where city_state ='$pid' ") or die(mysql_error()); ?>
<select name="cid" style="float:left; width:135px;">
<option value="">Select City</option>
<?php while($row=mysql_fetch_array($con)) {
$cid=$row['city_id'];
?>
<option value="<?=$cid?>" ><?php echo $row['city_name'] ?> <?php }?>
</option>
</select>
first table is country table, that coutry id is province_id,
second table is city, that Province id is city_state,
so, post value one to another dropdown
For this, you could use AJAX. In your country dropdown box, just echo all the countries in <option> elements.
Then attach a change event on this dropdown box using jQuery, so that it will take the user's input (I mean selected country) and do an AJAX request(jQuery has various shorthand methods for AJAX too) to fetch all the provinces belonging to this country. So this request will be sent to a PHP page on your site, that will pull the details from your db using the country id that the user selected.
Then the result from the AJAX request, which would be list of provinces with their IDs is dynamically appended to the second dropdown box(ie. for province). And for this province dropdown box also you would attach a change event to it, and do the similar thing like I mentioned above to fetch all the cities under this province, using AJAX.
Do a quick research on AJAX, in Google. There are lots of tutorials to help you.

How to get multiple drop-down box value using J-Query

I have generated drop-down box using loop. Now I want to get all value using J-Query for pass these value for insertion through Ajax.
My HTML CODE is:
<select name="travel[]" id="travel[]" >
<option value="1">Car</option>
<select>
<select name="travel[]" id="travel[]" >
<option value="2">Train</option>
<select>
<select name="travel[]" id="travel[]" >
<option value="3">Bus</option>
<select>
After click on Save button, how to collect all values of travel?
I don't understand why you define three <select> elements with an index-based name, each containing a single <option>. You do know that a <select> element is exactly that - it gives the user a selection?
With your current markup, the user doesn't get a choice about their selection - rather, travel[] will always be an array containing: 1,2,3.
You'd be better to modify your markup as follows:
<select name="travel" id="select_travel">
<option value="1">Car</option>
<option value="2">Train</option>
<option value="3">Bus</option>
<select>
Now you can easily access the value using:
$('#select_travel').val();
You can do this:
var data = $('select[name="travel[]"]').map(function () {
return $(this).val();
}).get();
console.log(data); // ["1", "2", "3"]
This will return you an array with the value for all the dropdowns.
Fiddle demo
why you are making name and id both as array type... i think one will enough if you really want to use array type.... then make id as unique for all...
<select name="travel[]" id="abc">
</select>
<select name="travel[]" id="def">
</select>
<select name="travel[]" id="xyz">
</select>
now you can access dropdown list easily..
$("#abc").val();
$("#def").val();
$("#xyz").val();
or else you can define uniq class for them if you really want array type id and name
<select name="travel[]" id="travel[]" class="abc">
</select>
<select name="travel[]" id="travel[]" class="xyz">
</select>
and try like this...
$(".abc").val();
$(".xyz").val();
hope it may help you
you should try js like-
var selectOption=$('#select_travel').val()
var Id=selectOption.getAttribute('id');
var name=selectOption.getgetAttribute('id');
now you can take output on button click

Categories