$.getJSON('getwarehousename',function(data){
for(var i=0;i<data.length;i++){
$("#plantname").val(data[0][0]);
var a = JSON.stringify(data[0][1]);
alert("PlantWH...."+a)
$("#plantwhname").val(a);
alert("wname.."+$("#plantwhname").val())
}
});
In this variable a value is plantwarehouse01, but this value can not be assigned to plantwhname id field?
$(document).ready(function() {
var html2="<label><select id='plantwhname' class='wname' name='store1'>";
var ht2="<option selected='selected'>Select</option>";
$("#plantware").html(html2);
$.getJSON('findPlantwarehouseForMultiple',function(data){
if(data!=0){
for(i=0;i<data.length;i++){
ht2+="<option>"+data[i].plantwarehousecode+"</option>";
}
ht2+="</select></label>";
$("#plantwhname").html(ht2);
$("#plantwhname").attr("Style","width:220px;");
}
});
});
i think your select option list and your new add option not same so new option not select so first add this option
$('#selectID').append($('<option>',
{
value: value_variable,
text : text_variable
}));
$.getJSON('getwarehousename',function(data){
for(var i=0;i<data.length;i++){
$("#plantname").val(data[0][0]);
var a = JSON.stringify(data[0][1]);
alert("PlantWH...."+a);
$('#plantwhname').append($('<option>',
{
value: a,
text : a
}));
$("#plantwhname").val(a);
alert("wname.."+$("#plantwhname").val())
}
});
then select it using this code. hope this will help you
Related
How can I bind data from controller to xml, My code is as follows,
View:
<Collection src="respondentAge"/>
<Label id="question"></Label>
Styles
".question":{
font:{
fontSize:18,
fontWeight:'normal'
},
color:"#000",
left:10,
height:Ti.UI.SIZE
}
Controller
var agenames = Alloy.Collections.respondentAge;
agenames.on("reset", function() {
var agenamesLength = agenames.length;
var question;
for (var i = 0; i < agenamesLength; i++) {
question = agenames.at(i).get("quesion");
// I need to bind the 'agenames.at(i).get("quesion")' value in to label in
}
});
agenames.fetch({
query:"SELECT * FROM respondentAge WHERE languageID ='1';"
});
The question text is coming from the database, So for for question I have added the label and I'm retrieving the value from database and I need to set the label value as retrieving value.
How can I do that
I propose you use the setText(text) property of Label. You can read more about it here: Label docs
agenames.on("reset", function() {
var agenamesLength = agenames.length;
var question;
for (var i = 0; i < agenamesLength; i++) {
question = agenames.at(i).get("quesion");
$.question.setText(question);
}
});
I have large form mainly drop down lists and checkboxes. Checkboxes are created dynamically so i don't know their id's before they are created. I use drop down onChange event to do create them on the fly.
How can i loop trough the form and get all the checkboxes that are checked, that is their id and their value? I need to do this only for check boxes that are checked. All checkboxes share the same name, that is: categoriesfilters[]. Currently i have on click event on the checkbox which invoke the javascript function.
Here is the code:
function update_number_of_adds_found(field_dropdown,selected_value) {
selected_value="";
var addtypeid = $("#addtypeid").val();
// trying to store the values of the checkboxes
$(this).find("input[type=checkbox]:checked").each(
function() {
var id = $(this).attr('id');
var value = $(this).val(); // or maybe attr('value');
// the data is stored, do whatever you want with it.
alert(value);
}
);
var selected_value = {
addtypeid: addtypeid,
// need to add the ids and the values here as well
};
var url = "<?php echo site_url('search/findNumberOfAdds'); ?>";
$.post(url, selected_value, function(r){
if(r) {
$('#totalNumOfAdds').empty();
$("#totalNumOfAdds").append(r.result);
} else {
// alert(selected_value);
}
}, 'json')
}
Regards, John
Try this :
var categories = [];
$("input[name='categoriesfilters[]']:checked").each(
function() {
var id = $(this).attr("id");
var value = $(this).val();
categories[categories.length] = {id : value};
}
);
console.log(categories);
$.post(url, categories, function(r){
...
Try this :
$('form').submit(function(){
$(this).find("input[type=checkbox]:checked").each(
function() {
var id = $(this).attr('id');
var value = $(this).val(); // or maybe attr('value');
// the data is stored, do whatever you want with it.
}
);
});
I guess you want to check that on form submit.
var arr = [];
$('input[name^="categoriesfilters"]:checked').each(function() {
var obj = {
id: $(this).attr('id');
value: $(this).val();
};
arr.push(obj);
});
console.log(arr); // show us the array of objects
Would you like to use Jquery?
Add a class to each of the checkbox i.e "class_chk";
$(function(){
$('.class_chk').each(function(){
if($(this).is(':checked')){
var id = $(this).attr('id');
var val = $(this).val();
alert("id = "+id+"---- value ="+val);
}
});
});
The above way you can get all the check box id and value those are checked.
Thanks..
I am trying to get the custom attribute values from the select box. It is triggered by a checkbox click which I already have working. I can get the name and value pairs just fine. I want get the custom attributes (therapy) (strength) (weight) and (obstacle) from the option value lines. is this possible?
select box
<option value="2220" therapy="1" strength="1" weight="0" obstacle="0">Supine Calf/Hamstring Stretch</option>
<option value="1415" therapy="0" strength="0" weight="0" obstacle="0">Sitting Chair Twist</option>
<option value="1412" therapy="0" strength="0" weight="0" obstacle="0">Static Abductor Presses</option>
jQuery
// exercise list filter category
jQuery.fn.filterByCategory = function(checkbox) {
return this.each(function() {
var select = this;
var optioner = [];
$(checkbox).bind('click', function() {
var optioner = $(select).empty().scrollTop(0).data('options');
var index=0;
$.each(optioner, function(i) {
var option = optioner[i];
var option_text = option.text;
var option_value = parseInt(option.value);
$(select).append(
$('<option>').text(option.text).val(option.value)
);
index++;
});
});
});
};
You need to find the selected , like this:
var $select = $('#mySelectBox');
var option = $('option:selected', $select).attr('mytag');
That is how to get selected option attribute:
$('select').find(':selected').attr('weight')
Get selected option and use attr function to get the attribute:
$("select").find(":selected").attr("therapy")
JSFIDDLE
how to change the selected value in javascript and get the selected value in codebehind page? AutoPostBack is set to false.
You can change it like this:
var ddl = document.getElementById('ddl-id');
var opts = ddl.options.length;
for (var i=0; i<opts; i++){
if (ddl.options[i].value == "some-value"){
ddl.options[i].selected = true;
break;
}
}
//setting the value of a drop down list
document.getElementById('my_drop_down').selectedIndex=2;
I have a list of checkboxes. Upon clicking on each of the checkboxes i am adding the value to the hidden variable. But the question is if I want to remove the value from the list upon unchecking the checkbox . How this piece cab be done
here is the hidden form variable
<input name="IDList[]" type="hidden" id="IDList" value="" />
and the jquery
$(".myCheckboxClass").change(function() {
var output = 0;
$(".myCheckboxClass").change(function() {
if ($(this).is(":checked")) {
output += ", " + $(this).val();
} else {
output = $.grep(output, function(value) {
return value != $(this).val();
});
}
$("#IDList").val(output);
});
});
Something like this: (demo) http://jsfiddle.net/wesbos/5N2kb/1/
we use an object called vals to store the info. ADding and removing as we check/uncheck.
var vals = {};
$('input[type=checkbox]').click(function() {
var that = $(this);
if (that.is(':checked')) {
console.log(this.name);
vals[this.name] = "In your Object";
}
else {
delete vals[this.name];
}
console.log(vals);
});
Following your logic, you could do this:
$('#IDList').data('value', []);
$(".myCheckboxClass").change(function() {
var list = $('#IDList').data('value');
if ($(this).is(":checked")) {
list.push($(this).val());
} else {
var indexToRemove = list.indexOf($(this).val());
list.splice(indexToRemove, 1);
}
$('#IDList').val(list);
});
But if you only care about the value of #IDList upon data submission or other actions, you probably want to consider an alternative approach: collating the checked values when you need them.
$('#form').submit(function() {
var list = $('input.myCheckboxClass:checked', this).map(function() {
return $(this).val();
}).get();
$('#IDList').val(list);
});
See both of the above in action: http://jsfiddle.net/william/F6gVg/1/.