Is there a way to remove the first options from this script:
http://javascript.internet.com/navigation/connected-comboxes.html
I want to remove the [ Type ] and [ Style ] options from the list and display other options only...
Can anyone please help?
Remove the following lines:
document.product.id_type.options[0] = new Option("[ Type ]");
document.product.id_style.options[0] = new Option("[ Style ]");
In addition to what is already suggested do some tweaks in code, set 1 =0 and if you also want to remove first empty option from second combo use j = 0
================================
function init(sel_type, sel_style){
for(i = 0; i <= TypeArray.length; i++){
document.product.id_type.options[i] = new Option(TypeArray[i].type, TypeArray[i].id);
if(TypeArray[i].id == sel_type)
document.product.id_type.options[i].selected = true;
}
OnChange(sel_style);
}
function OnChange(sel_style){
sel_type_index = document.product.id_type.selectedIndex;
sel_type_value = parseInt(document.product.id_type[sel_type_index].value);
for(i = document.product.id_style.length - 1; i > 0; i--)
document.product.id_style.options[i] = null;
j=1;
for(i = 0; i <= StyleArray.length; i++){
if(StyleArray[i].id_type == sel_type_value){
document.product.id_style.options[j] = new Option(StyleArray[i].style, StyleArray[i].id);
if(StyleArray[i].id == sel_style) document.product.id_style.options[j].selected = true;
j++;
}
}
}
Related
Im getting this error and i dont understand why. Please help.
What Im trying to do is loop through all the options on a multiselectlist.
HTML/Razor
#Html.ListBoxFor(model => model.SelectedUsersIdsArray, new MultiSelectList(Model.Users, "ID", "NAME"), new { id = "Select", multiple = "multiple" })
JavaScript
var filterFuncionarios = [];
#foreach (var f in Model.Funcionarios)
{
#:filterFuncionarios.push({ Id: "#f.ID"})
}
var selecionados = $('#usersSelectDropdown')[0].options;
function filtraListDeFuncionarios() {
for (var i = 0; i < this.selecionados.length; i++) {
for (var k = 0; k < filterFuncionarios.length; i++) {
if (selecionados[i].value == filterFuncionarios[k].Id) {
selecionados[i].selected = true;
}
}
}
}
This is the exact code im running.
Error
Uncaught TypeError: selecionados[i] is undefined
You're already reading the options array here:
var select = $('#Select')[0].options;
Which you loop over:
for (var i = 0; i < select.length; i++) {
But then you try to read another options property on that same array:
if (select.options[i].value == filterFuncionarios[k].Id) {
select.options[i].selected = true;
}
Overall you've confused yourself with poor variable names. The initial variable is called "select" but it isn't a "select". It's an array of options. So call it that:
var options = $('#Select')[0].options;
Then looping over it is more intuitive:
for (var i = 0; i < options.length; i++) {
And accessing each option is clear:
if (options[i].value == filterFuncionarios[k].Id) {
options[i].selected = true;
}
You've received options in select definition,
var select = $('#Select')[0].options;
then you trying to access options in for
select.options[i].selected = true; will be equal to $('#Select')[0].options.options;
I suggest you to remove .options from $('#Select')
I have a logic like i have four checkboxes which should behave as existed code. Logic is working. But i do check and uncheck using the syntax.
angular.element(document.querySelector('#c_'+j)).attr('checked', true);
angular.element(document.querySelector('#c_'+j)).attr('checked', false);
which is not reflected in the respective checkbox element's model value. As you can check the attached screen shot. First three box got checked but it shows 'true' for actual clicked element rest remains 'false'. I need the updated model values. Anyone can help on this !
Here is the working example https://plnkr.co/edit/zA5V9gc6jTpPq3pIuvC8?p=preview
You should operate on $scope inorder to achieve two-way binding.
So, your function will change to,
function rangeCal(arg, bool){
var tmparray= [];
var selectedcheckbox;
for(var propt in arraymatrix){
tmparray = arraymatrix[propt];
for(var i=0; i <= tmparray.length; i++){
if(month === tmparray[i]){
selectedcheckbox = propt;
var a = 'c_'+selectedcheckbox;
$scope[a]= true
var gap = arg.split('_')[1];
if(!bool){
for(var j=propt; j<= gap; j++){
var j = 'c_'+j;
$scope[j]= true
}
}else if(bool) {
for(var k=propt; k<= gap+1; k++){
if(k > gap){
var k = 'c_'+k;
$scope[k]= false
}
var j = 'c_'+j;
$scope[j]= true
}
}
}
}
}
HERE IS THE WORKING PLUNKER
You can replace
angular.element(document.querySelector('#c_'+j)).attr('checked', true);
with
var index = 'c_'+j;
$scope[index]= true
and same process to make it unchecked by putting false in place of true
Check this snippet, hope this is what you were looking for. It is working for both actions, checking and unchecking.
function rangeCal(arg, bool){
var tmparray= [];
var selectedcheckbox;
for(var propt in arraymatrix){
tmparray = arraymatrix[propt];
for(var i=0; i < tmparray.length; i++){
if(month === tmparray[i]){
selectedcheckbox = propt;
angular.element(document.querySelector('#c_'+selectedcheckbox)).attr('checked', true);
var gap = arg.split('_')[1];
if(!bool){
for(var j=propt; j<= gap; j++){
var cb_id = "c_"+j;
$scope[cb_id] = true;
// angular.element(document.querySelector('#c_'+j)).attr('checked', true);
}
}else if(bool) {
for(var k=4; k>= gap; k--){
var gap_id = "c_"+k;
$scope[gap_id] = false;
// angular.element(document.querySelector('#c_'+gap)).attr('checked', false);
}
}
}
}
}
setTimeout(function(){
console.log($scope);
}, 2000);
}
I am trying to write a script that will convert all characters to lowercase if a particular nested style is applied. I can't seem to figure out the correct syntax to get the text.
I originally tried the following, which worked to an extend, but lowercased the entire paragraph rather than only the text that has the character style applied:
function lowerCaseNest(myPStyle, myCStyle){
var myDocument = app.documents.item(0);
//Clear the find/change preferences.
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeTextOptions.caseSensitive = false;
app.findChangeTextOptions.includeFootnotes = false;
app.findChangeTextOptions.includeHiddenLayers = false;
app.findChangeTextOptions.includeLockedLayersForFind = false;
app.findChangeTextOptions.includeLockedStoriesForFind = false;
app.findChangeTextOptions.includeMasterPages = false;
app.findChangeTextOptions.wholeWord = false;
app.findTextPreferences.appliedParagraphStyle = myPStyle;
var missingFind = app.activeDocument.findText();
var myDoc = app.documents[0];
for ( var listIndex = 0 ; listIndex < missingFind.length; listIndex++ ) {
for (i = missingFind[listIndex].nestedStyles.length-1;i>=0; i--) {
for (j = missingFind[listIndex].nestedStyles[i].parent.characters.length-1;j>=0; j--) {
if (missingFind[listIndex].nestedStyles[i].parent.characters[j].contents.appliedCharacterStyle(myCStyle)) {
var myString = missingFind[listIndex].nestedStyles[i].parent.characters[j].contents;
if (typeof(myString) == "string"){
var myNewString = myString.toLowerCase();
missingFind[listIndex].nestedStyles[i].parent.characters[j].contents = myNewString;
}
}
}
}
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
}
I then tried playing around with appliedNestedStyles, but can't seem to figure out how to retrieve the text that the nested style is applied to.
Could anyone help with this?
Thanks!
John
Unless I am wrong the appliedNestedStyle can be looked after in the F/C dialog by targeting the applied characterStyle:
GREP
Find : .+
Format : character style => myCharStyle
then
var found = doc.findGrep();
…
I actually took a different tack, and figured out something that works:
function lowerCaseNest(myPStyle, myCStyle){
for (var i = 0; i < app.activeDocument.stories.length; i++){
for (var j = 0; j < app.activeDocument.stories[i].paragraphs.length; j++){
var myP = app.activeDocument.stories[i].paragraphs[j];
if (myP.appliedParagraphStyle.name==myPStyle) {
for (k=0; k<myP.characters.length; k++) {
if(typeof(myP.characters[k].appliedNestedStyles[0]) != 'undefined'){
if(myP.characters[k].appliedNestedStyles[0].name == myCStyle) {
var myC = myP.characters[k].contents;
if (typeof(myC)=='string'){
var myNewString = myC.toLowerCase();
myP.characters[k].contents = myNewString;
}
}
}
}
}
}
}
}
Still would be interested in knowing if there's an easier way to handle this, as I'm afraid this may take longer to run on long documents, since it's dealing with every paragraph individually.
I have a select tag to choose categories, each option contain the category number as value.
The category number is in the URL string.
I'm trying to write a JS to check if the option value is the same as the category number in the URL and if so make the option selected. so far the script dosnot work.
What am I doing wrong?
here is the code:
function GetUrlValue(VarSearch){
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
for(var i = 0; i < VariableArray.length; i++){
var KeyValuePair = VariableArray[i].split('=');
if(KeyValuePair[0] === VarSearch){
return KeyValuePair[1];
}
}
}
function compareValue(){
var x = document.getElementById("selectcategory").length;
for (var i = 0; i < x; i++){
var categNo = document.getElementById("selectcategory").options[i];
var UrlValue1 = GetUrlValue('icid');
if (categNo === UrlValue) {
document.getElementById("selectcategory").options[i].selected = true;
}
alert(UrlValue1);
}
}
if needed, I will send a link to the work.
if doing that with jquery is easier, i will be happey to learn.
thanx.
The problem is that categNo should be the value of the corresponding option tag. Also it's better to cache select element and not requery DOM in the loop:
function compareValue() {
var select = document.getElementById("selectcategory");
var x = select.options.length;
for (var i = 0; i < x; i++) {
var categNo = document.getElementById("selectcategory").options[i].value;
var UrlValue = GetUrlValue('icid');
if (categNo === UrlValue) {
select.options[i].selected = true;
}
}
}
Demo: http://jsfiddle.net/dj7c6sdL/
Does anyone know how to remove selected items from an array?
var view:NotesView = getComponent("viewPanel2");
var UtbildningarArray = new Array();
viewScope.col = view.getSelectedIds();
if (viewScope.col.length > 0){
for (i=0; i<viewScope.col.length; i++){
var docid = viewScope.col[i];
if (docid != null) {
var doc = database.getDocumentByID(docid);
UtbildningarArray.push(doc.getItemValueString("Namn"))
}
}
}
document1.removeItemValue("Utbildningar",UtbildningarArray);
document1.save();
I have tried, removeEntry and splice but I don't get it work.
Thanks,
Jonas
Edit:
You are right, have added this in the code:
var view:NotesView = getComponent("viewPanel2");
var UtbildningarArray = new Array();
var UtbildningarArray = new Array();
var FieldUtbArray = new Array(getComponent('inputHidden1').getValue());
viewScope.col = view.getSelectedIds();
if (viewScope.col.length > 0){
for (i=0; i<viewScope.col.length; i++){
var docid = viewScope.col[i];
if (docid != null) {
var doc = database.getDocumentByID(docid);
UtbildningarArray.push(doc.getItemValueString("Namn"))
}
}
}
document1.replaceItemValue("Utbildningar",FieldUtbArray.slice(UtbildningarArray));
document1.save();
I'm saving what the user selected in a hidden input, and when the user clicks the "Remove programs" button I display the selected courses in the view. Then should the user be able to click a checkbox and remove the selected course(s). Now when I save nothing happens.
I think you need to show more what you want to remove.
Below you have to code snippets that will remove an entry from an js array.
http://openntf.org/XSnippets.nsf/snippet.xsp?id=remove-an-entry-from-an-array-of-strings
http://dontpanic82.blogspot.se/2010/10/code-snippet-arraysplice-according-to.html
I got it work!
for (var i = 0; i < FieldUtbArray.length; i++) {
found = false;
// find a[i] in b
for (var j = 0; j < UtbildningarArray.length; j++) {
if (FieldUtbArray[i] == UtbildningarArray[j]) {
found = true;
break;
}
}
if (!found) {
result.push(FieldUtbArray[i]);
}
}