1

I have a form to record/update some information for a book. There is a text box which contains only the file path and another textbox for attached file's path.

<input type="text" id="image" name="set[image]" value="<?=$document->image?>" />
<input type="button" value="Choose Image" onclick="BrowseServer('image');" />

<input type="text" id="attachment" name="set[attachment]" value="<?=$document->attachment?>" />
<input type="button" value="Choose File" onclick="BrowseServer('attachment');" />

Both call BrowseServer() function:

function BrowseServer(field) {
    var finder = new CKFinder();
    finder.basePath = 'repo/';
    finder.selectActionFunction = SetFileField; 
    finder.popup();
}

function SetFileField(fileUrl) {
    document.getElementById('attachment').value = fileUrl;
}

First, there was only one field (Choose File). Then I've decided to add another to select image path in the same way. And I have modified the SetFileField(fileUrl) function:

function SetFileField(fileUrl, fieldName) {
    document.getElementById(fieldName).value = fileUrl;
}

This does not work as I guessed. How can I pass field name to SetFileField function?

I have duplicated both functions for image and attachment as BrowseServerForFile(), SetFileField() and BrowseServerForImage(), SetImageField().

It works. But this is not so efficient.

zkanoca
  • 9,664
  • 9
  • 50
  • 94

0 Answers0