Inserting Checkbox with Javascript


Hi All


Kindly of a problem I'm facing. Using Ember Media Manager, I exported my list of movies in custom template. The template is amazing shows exactly what a viewer would like to see on my collection.


Now I have friends who are asking to place a checkbox next to every movie name so, once they are done with their selection, so I receive and email with their movie selection they want from me. Ofcourse happens via form.


Here's the problem, my movie list (navigation panel) get populated based on user's genre selection, search queries and by default all. So, basically the number of movies will always differ.


I wanted to know if there was a way that when the site visitor clicked for e.g. Horror and 15 movies were populated in the left navigation pane, could I be able to somehow add 15 checkboxes next to them. And ofcourse if another genre is selected then add the same amount of checkboxes as per the number of movies.


Thanks  

E
its kind difficult to understand in my POV but not impossible  

imagining it while reading


can you show some codes? or samples on what you want to achive?
giving a name to checkboxes means grouping them together to the same question

if you have 10 questions, and each has 5 checkboxes, and you don’t group them together, that would mean having 50 checkboxes lumped together - maybe you have also pretty similar values etc…

you give each checkboxes group… You could achieve this with a simple `for` loop:



```
var min = 12,
    max = 100,
    select = document.getElementById('selectElementId');

for (var i = min; i<=max; i++){
    var opt = document.createElement('option');
    opt.value = i;
    opt.innerHTML = i;
    select.appendChild(opt);
}

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/).


[JS Perf](https://jsperf.com/) comparison of both mine and [Sime Vidas' answer](https://jsperf.com/comparison-of-loops), run because I thought his looked a little more understandable/intuitive than mine and I wondered how that would translate into implementation. According to Chromium 14/Ubuntu 11.04 mine is somewhat faster, other browsers/platforms are likely to have differing results though.







**Edited** in response to comment from OP:



> 
> [How] do [I] apply this to more than one element?
> 
> 
> 



```
function populateSelect(target, min, max){
    if (!target){
        return false;
    }
    else {
        var min = min || 0,
            max = max || min + 100;

        select = document.getElementById(target);

        for (var i = min; i<=max; i++){
            var opt = document.createElement('option');
            opt.value = i;
            opt.innerHTML = i;
            select.appendChild(opt);
        }
    }
}
// calling the function with all three values:
populateSelect('selectElementId',12,100);

// calling the function with only the 'id' ('min' and 'max' are set to defaults):
populateSelect('anotherSelect');

// calling the function with the 'id' and the 'min' (the 'max' is set to default):
populateSelect('moreSelects', 50);

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/1/).


And, finally (after quite a delay...), an approach extending the prototype of the `HTMLSelectElement` in order to chain the `populate()` function, as a method, to the DOM node:



```
HTMLSelectElement.prototype.populate = function (opts) {
    var settings = {};

    settings.min = 0;
    settings.max = settings.min + 100;

    for (var userOpt in opts) {
        if (opts.hasOwnProperty(userOpt)) {
            settings[userOpt] = opts[userOpt];
        }
    }

    for (var i = settings.min; i <= settings.max; i++) {
        this.appendChild(new Option(i, i));
    }
};

document.getElementById('selectElementId').populate({
    'min': 12,
    'max': 40
});

```

[JS Fiddle demo](https://jsfiddle.net/davidThomas/NX3ac/148/).


References:


* [`node.appendChild()`](https://developer.mozilla.org/en/DOM/node.appendChild).
* [`document.getElementById()`](https://developer.mozilla.org/en/DOM/document.getElementById).
* [`element.innerHTML`](https://developer.mozilla.org/en/DOM/element.innerHTML). i just figured out what the problem was. if you enable the “titlebar” in firefox’s “customize…” window (it is a checkbox at the bottom) then the traditional window titlebar appears (with the buttons on the left) and the click and drag thing works. who knew? if you visit admin > customize > embedding you can change “maximum number of posts to embed” to a higher value. besides what [@trevorhodges](/u/trevorhodges) said with [codepen.io](http://codepen.io), you can use a about:blank. next inspect, then add your code. my browser is generally chrome, and it works for me. you should have three choices.

 thanks for the update...i'll check it out. Hi Jan,


years ago John Hawkinson did a script that would invoke the place options on an already placed PDF, InDesign page or AI file, I think. Hope, I can find the old thread or the ExtendScript code. You could build on this. But be warned: Not all PDFs would show how many pages are inside. At least you cannot see this by scripting.


 


Ah. Found the extended script I did, based on John's original one:


 


 



```
// PlaceAgain-PlaceOptionsShowing-SELECTION.jsx
// Uwe Laubender

//DESCRIPTION:Select a placed image, PDF or InDesign document to replace it with itself getting options

/**
* @@@BUILDINFO@@@ PlaceAgain-PlaceOptionsShowing-SELECTION.jsx !Version! Fri Sep 09 2016 14:09:53 GMT+0200
*/

/*
	Posted in this thread at Adobe InDesign Forum:
	"Toggle pages of a linked Indesign document inside Indesign?"
	mmackinven | Sep 9, 2016
	https://forums.adobe.com/message/8993859#8993859
	
	You can either select the placed file directly or its container frame.
	Or, if its part of a group, the group itself.
	Or, if the container frame is pasted inside another object, that object.
	
*/

placeAgainSelection();

function placeAgainSelection()
{
	if(app.documents.length == 0){alert("ERROR"+"\r"+"No document is open."); return};
	if(app.selection.length != 1){alert("ERROR"+"\r"+"Select one single item containing a placed file."); return};

	// The placed object is selected:
	if
	(
		app.selection[0].constructor.name == "ImportedPage" || 
		app.selection[0].constructor.name == "PDF" ||
		app.selection[0].constructor.name == "EPS" ||
		app.selection[0].constructor.name == "Image" ||
		app.selection[0].constructor.name == "PICT" ||
		app.selection[0].constructor.name == "WMF"
	)
	{	
		var graphic = app.selection[0];
	};
	
	else if(app.selection[0].allGraphics.length == 0){return};
	
	// The container of the placed object is selected:
	else{var graphic = app.selection[0].allGraphics[0]};

	// Two important checks:
	// Case 1: Graphic was pasted on the page from e.g. PhotoShop:
	if(graphic.itemLink == null){alert("ERROR"+"\r"+"The graphic was pasted on the page. The original file cannot be found.");return};
	// Case 2: Link is not available, because placed graphic was renamed, removed or otherwise is not available:
	var file = File(graphic.itemLink.filePath);
	if(!file.exists){alert("ERROR"+"\r"+"\""+file.name+"\""+"\r"+"File cannot be found."); return};
	
	// If you cancel the place options dialog, no error will be thrown:
	try{
	graphic.place(file,true);
	}catch(e){};
};
```

 


 


**Important Note:**


The original thread from 2016 where I posted the script code did not make it to the new InDesign forum.


 


Because of that this thread where I mentioned my script is rendered useless:


[https://community.adobe.com/t5/indesign/swapping-pages-of-a-linked-file-indesign-file-without-replac...](https://community.adobe.com/t5/indesign/swapping-pages-of-a-linked-file-indesign-file-without-replacing-the-file-and-choosing-the-page/m-p/10403771?page=1)


 


This one as well, but there is also a link to a script by Roland Dreger that could be useful:


<https://community.adobe.com/t5/indesign/linked-ai-file-change-artboard/m-p/10444575?page=1>


 


Regards,  
Uwe Laubender


( ACP ) I had the same problem a couple of months back. Now if this is happening only with Chrome and not with other browsers, then the problem cannot be a virus. But it can be a virus if other browsers and programs are facing equal problems.  
  
So, with chrome as we all know there is a memory problem. So to solve that follow these simple steps.  
  
1. On the top right menu icon, select History  
2. From there select "clear browsing data"  
3. It will prompt for the time span, there you select "beginning of time"  
4. You might lose few data like saved passwords, favorites, but no data will be removed which are saved properly.  
  
After you are done with this, clean your system with Disk Cleaning Software. While doing this don't keep any browser window open especially Chrome.  
If you notice, it is skipping out the Chrome from the list, you have to select the program manually and click on "clear".  
  
After this restart your system and see if it works. If it doesn't then you have to undergo the entire process of uninstalling and re-installing Chrome. send me a message and i'll see what we can do for you.
 


  
 


 be sure to include a description of the issue, your username, and the error message you are prompted with when you attempt to create a ticket.
 


  
 


 received your message. topic locked. hmm.  you can use ticket rules to mute the ticket as soon as it gets created.  you can have it look for tickets from that particular email address and mute them as they come in.