-1

I use Roxy Fileman to manage images and files in my CMS. The filemanager has a custom option to insert files from a text field with a button. When the button is clicked the filemanager open. This option is based on the text field ID. My problem is that I have multiple text fields so I have made the ID:s unique. But how can I add these ID to txtFieldId in the path?

This is the first text field with ID 1

<input type="text" name="img" id="txtSelectedFile1" class="textfield" >
<button class="btn btn-default" onclick="openCustomRoxy2()" type="button">Select image</button>

The second one with ID 2

<input type="text" name="document" id="txtSelectedFile2" class="textfield" >
<button class="btn btn-default" onclick="openCustomRoxy2()" type="button">Select image</button>

Here's the div with the iframe that opens the filemanager when the button is clicked. This is where I need to add the ID:s to the txtFieldId.

<div id="roxyCustomPanel2" style="display: none;">
<iframe src="/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile" style="width:100%;height:100%" frameborder="0">
</iframe>

So i finally manage to solved it with help from thedarkone. The different from the answer in the link is that I left the ID in the text field unchanged and added the src function to the button.

<script>
function go(pth) {
  document.getElementById('roxy').src = pth;
}
</script>

<div id="roxyCustomPanel2" style="display: none;">
  <iframe id="roxy" src="about:blank" style="width:100%;height:100%" frameborder="0"></iframe>
</div>

<input type="text" name="img" id="txtSelectedFile1" class="textfield">
<button class="btn btn-default" onclick="openCustomRoxy2(); go('/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile1');" type="button">Select image</button>

<input type="text" name="document" id="txtSelectedFile2" class="textfield">
<button class="btn btn-default" onclick="openCustomRoxy2(); go('/fileman/index.html?integration=custom&type=files&txtFieldId=txtSelectedFile2');" type="button">Select image</button>
perqedelius
  • 105
  • 1
  • 1
  • 10

1 Answers1

0

What I could get from your use case, would probably be best solved by this answer. It has both a JS solution and an pure html solution. I would prefer JS as you wouldn't have to write the whole src in each, and you are already doing that, seeing that your are using functions.

Changing iframe src with Javascript

Community
  • 1
  • 1
thedarkone
  • 402
  • 3
  • 10
  • The idea seems good but when I try it the iframe opens but doesn't load the editor. So i beleive the src doesn't get loaded to the function. Will the onselect (I even tried the onclick) work on the text field even if I click the button? – perqedelius Oct 26 '16 at 20:59
  • Well your solution seems good, however it can be optimized a little, but that's if this is about more than a trial thing. – thedarkone Oct 27 '16 at 01:54