in need your help. i have option select:
Relationship:
<?php
$relationship=array(
''=>'Choose relationship',
'child'=>'child',
'guardian'=>'guardian',
'parent'=>'parent',
'wife'=>'wife',
'husband'=>'husband',
'mother in law'=>'mother in law',
'futher in law'=>'futher in law'
);
echo form_error('relationship');<br />
echo form_dropdown('relationship', $relationship, set_value('relationship'), array('id'=>'relationship'));
?>
how can i make input box to appear if selection is made? example if i choose mother i want input box for address to appear, if i choose child i want input box for birth date to appear...
trigger an event when an option is selected, then check which option was selected and display the input box accordingly.
for example:
$('selectbox').on('change', function (e) {
if( this.value == 'mother')
{
$('addressinput').show();
}
});
Related
I'm trying to fill a dropdown box in a form with items from a database.
But it only has to fill with the data from a database that is equals to the previous input field.
Let's pretend that i have a database that looks something like this:
and my from looks like this:
<body>
<form>
<input id="nummer">
<span></span>
<select name="name">
<option>name</option>
</select>
</form>
</body>
i have already found a way to fill the dropdown boxes with data with this js code but this is without a database:
$(document).ready(function()
{
$nummer = $("select[name='nummer']");
$name = $("select[name='name']");
$input = $(this).val();
$('#nummer').bind('input', function()
$(this).next().stop(true, true).fadeIn(0).html('[input event fired!]: ' + $(this).val());
if ($(this).val() == "123")
{
$("select[name='categorie'] option").remove();
$("<option>Pieter</option>").appendTo($categorie);
$("<option>Steven</option>").appendTo($name);
}
});
});
When i enter 123 in the number input field i need the dropdown box filled with peter and steven
Is this possible?
Program the input field's onblur event to look for a dropdown item with the matching value. If found, mark the found dropdown value as selected.
$(document).ready(function(){
$(document).on('#inputfield', 'blur', function(){
$.ajax(
//Properties
//Current value of the input field should be sent to the server
data:{inputValue:$('#inputfield').val()}, //Use this in where clause in the server
success:function(){
// Populate the data into the dropdown
}
);
}
})
Here I have outlined what you need to do.
If I fill out the rest, it will be Me programming for you. And the necessary information is also not there for me to fill out the rest.
See this image
I am using Image Picker plugin to select the image. I have an empty text area field below images. When user click an image, I want the value/description of that image to automatically copied to that field and also being able to edit.
And when I click un select that image, the field below should become empty.
I have got it working to some extent .
Problem
When I select image, the description get's copied into the field. which is fine. But when I un-select the same image, the description still stays there. And when I select different image, the description of different image than doesn't gets copied.
Here is my code.
HTML:
Images come from database.
<select class='image-picker timer-reasons' multiple="multiple" data-limit="1" name="timer-reason-selector" id="timer-reason-selector">
<?php
while ($row = mysqli_fetch_assoc($timer_reasons)) {
?>
<option data-img-src='../../css/timer-reasons/<?php echo $row['image_tmr']; ?>' style="width:30%;" value='<?php echo $row['description_tmr']; ?>'><?php echo $row['description_tmr']; ?></option>
<?php
}
?>
</select>
This is field where clicked image description/value should get populated and also editable
<textarea class="form-control" id="reason" value="" rows="2"></textarea>
I am using "Image-picker" class
JavaScript
This is my JavaScript
<script>
$(document).ready(function(){
//Set up the imagepicker select field
$("#timer-reason-selector").imagepicker({
limit:1,
hide_select:true,
show_label:false,
limit_reached:function(){
}
});
function check_enabled(){
//Get the value of the selected options
var timer_reason = $( "#timer-reason-selector" ).val();
if (timer_reason !=null){
$("#reason").text(timer_reason);
$("#reason").attr('value', timer_reason)
}else{
$("#reason").text('');
$("#reason").attr('value', '')
}
}
//Listen for selection changes and call the check_enabled function
$( "#timer-reason-selector" ).change(function() {
check_enabled();
});
});
</script>
According to the documentation you can use changed event of imagepicker itself like this:
$("#timer-reason-selector").imagepicker({
limit:1,
hide_select:true,
show_label:false,
limit_reached:function(){
},
changed: function(select, newValues, oldValues, event) {
// Do your stuff here
}
});
I have a select area for the user:
<select class="span12" placeholder="Enquiry Type" name="enquiry" id="enquiry">
<option value='' selected></option>
<option value='cv'>Submit CV</option>
<option value='vacancy'>Submit Vacancy</option>
</select>
I have a hidden field in the form which allows the user to upload their cv. I now need it so that if the user selects submit cv, the field will display itself.
<input type="file" name="cv" accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" style="display:none;">
I know that i would be able to check the user input of the select using an on click function. Is there a way of doing it without that (there and then)? And then if that option is selected, display the hidden file upload.
Try this:
$('#enquiry').on('change', function(e) {
if($(this).val() === "cv") {
$('input[name="cv"]').show();
}
});
This works:
http://jsfiddle.net/dL8evt33/
:)
You can achieve this by hooking to the change event of the select and checking the selected value. You can then use toggle() to hide or show the input as needed. Try this:
$('#enquiry').change(function() {
$('input[type="file"]').toggle($(this).val() == 'cv');
});
Example fiddle
remove display: none; first now do write this code.
$("[id$=fileupload]").hide();
if("[id$=enquiry]").val('cv')
{
$("[id$=fileupload]").show();
}
else
{
$("[id$=fileupload]").hide();
}
On change event you can display the input type file using its id. Give 'file' as id to hidden field -
$('#enquiry').on('change', function() {
if("cv" == this.value){
jQuery("#file").show(); // or jQuery("#file").toggle();
}
});
I'm hoping you can please help.
I have the following HTML code:
<select id='bonus1frequency'>
<option value="0">Annual</option>
<option value="1">Half Yearly</option>
<option value="2">Quarterly</option>
</select>
Depending on what option is selected, fields are displayed in a divider. For example if you select annual, a field to enter annual bonus is displayed. If you select 'Half Yearly' two fields to enter two half yearly bonuses are displayed.
The trouble I'm having is that if you select 'Half yearly' for example, then enter what the half yearly bonus into the fields, then you change your mind and decide you want to enter an annual bonus instead, the values that you enter into the half yearly bonus are retained. I need them to be set to zero when you switch between options in the html select box.
I tried the following code to help with this but it's not working and i'm not sure why. All it does is prevent me from putting anything at all into the half year boxes.
var bonus_val_1 = document.getElementById("bonus1frequency");
var strUser = bonus_val_1.options[bonus_val_1.selectedIndex].value;
if (strUser = "0") //if annual bonus is selected
{
document.getElementById("halfyear_bonus_one").value = 0.00;
}
Edit:
I'm using the following JQUERY in the main HTML document to actually switch what fields are displayed when the user selects each option. So if the user selects option value 0 'annual' in the select box, the following code will show the annual bonus divider containing the annual bonus field, and hide the dividers that show half yearly and quarterly bonus fields.
Based on comments about how I need to tie resetting these fields to the change event, I just thought maybe I can reset the fields to zero within the following jquery code. However I'm even less familiar with JQUERy and not sure how to do that...any help would be much appreciated.
$('#bonus1frequency').on('change', function() {
if ( this.value == '0')
//.....................^.......
{
$("#annual").show();
$("#halfyearly").hide();
$("#quarterly").hide();
}
if ( this.value == '1')
//.....................^.......
{
$("#annual").hide();
$("#halfyearly").show();
$("#quarterly").hide();
}
EDIT 2
I have updated the code as follows:
$('#bonus1frequency').on('change', function() {
if ( this.value == '1')
//.....................^.......
{
$("#annual").show();
$("#halfyearly").hide();
$("#quarterly").hide();
$("#halfyear_bonus_one").val("0");
This prevents me from entering a value into the halfyear bonus one field. It just keeps resetting the value to zero. I've added an empty 'choose' option to the select box but it hasn't made a difference. Any ideas?
Please refer following for help and add code for quarterly. Use jquery instead of using javascript code to get elements.
<select id="bonus1frequency">
<option value="0">Annual</option>
<option value="1">Half Yearly</option>
<option value="2">Quarterly</option>
</select>
<div id="annual" style="display: none;">
<input type="text" id="a1">
</div>
<div id="half" style="display: block;">
<input type="text" class="b2">
<input type="text" class="b2">
<script>
$('#half').hide()//Same as this hide quarterly div
$("#bonus1frequency").change(function(){
var strUser = $(this).val()
if (strUser === "0") //if annual bonus is selected
{
$('#annual').show()
$('#half').hide()
$(".b2").val(0);
}else{
$('#half').show()
$('#annual').hide()
$('#a1').val(0)
}
})
</script>
</div>
The problem with your code is that you're not binding it to the select's change event. It will run when loading the page, and since the default option in the dropdown is "Annual", the value which will appear as the value of #halfyear_bonus_one would be 0.00 and won't change, even if the user will choose another option in the dropdown.
You should create a js function which contain your code (with few corrections)
and then bind it to a change event of the dropdown.
Moreover, you should add conditions to handle the other scenarios: "half yearly" and "quarterly".
var bonusval1 = document.getElementById("bonus1frequency");
bonusval1.onchange = function () {
var strUser = bonusval1.options[bonusval1.selectedIndex].value;
if (strUser == "0"){ //if annual bonus is selected
document.getElementById("halfyear_bonus_one").value = "0.00";
} else if(strUser == 1){ //Half yearly is selcted
document.getElementById("halfyear_bonus_one").value = "1.00";
} else { //quertly is selected
document.getElementById("halfyear_bonus_one").value = "2.00";
}
}
Now, there's another problem - the default value is the first value - but the "onchange" event won't trigger. We can run the function outside of the onchange event in order to handle the default value or you can add a blank option to the dropdown as the first option, something like "Choose:" or whatever.
Jsfiddle
Regarding the second question
I didn't understand why would you use jQuery all of a sudden when you already
wrote pretty good js code. Those kind of decisions should be considered in the beginning of the process.
Anyway, You can use the .val() function to change the value of the input fields. I don't have the code of your form and the dividers but it should be pretty much like the following:
if ( this.value == '0')
//.....................^.......
{
$("#annual").show();
$("#halfyearly").hide();
$("#quarterly").hide();
$("#id_of_input_for_halfyearly").val("0");
$("#id_of_input_for_quarterly").val("0");
}
I think this will help you out.
jQuery('#bonus1frequency').on('change',function(){
if(this.value==1){
jQuery('.yearly').val('').show();
jQuery('.half-yearly').val(0).hide();
jQuery('.quarterly').val(0).hide();
}else if(this.value==2){
jQuery('.yearly').val(0).hide();
jQuery('.half-yearly').val('').show();
jQuery('.quarterly').val(0).hide();
}else if(this.value==3){
jQuery('.yearly').val(0).hide();
jQuery('.half-yearly').val(0).hide();
jQuery('.quarterly').val('').show();
}
})
Check this Demo
Is it possible to select a specified value from a combo box by clicking on a button.
option 1:
Suppose you want to set value to 3 in your dropdown named 'sel'
<input type="button" value="set to 3" onclick="document.getElementById('sel').value = 3" />
option 2:
If you want to set specific text (say 'myvalue') as selected display text (which already exists in the dropdown list), then you can use loop
for (i=0;i<document.getElementById('sel').length;i++)
{
if ('myvalue' == document.getElementById('sel').options(i).text)
{
document.getElementById('sel').options(i).selected = true;
return;
}
}