This is a migrated thread and some comments may be shown as answers.

Set description field to uploaded filename

1 Answer 58 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 15 Nov 2011, 07:03 PM
I had a requirement to set my description field to the uploaded filename. I used the additional field example supplied by Telerik.
Here is how I set that value:

<telerik:radupload id="RadUpload1" runat="server" onclientadded="addTitle" onclientfileselected="uploadFileSelected" />

<script type="text/javascript" language="javascript">
    function uploadFileSelected(sender, args) {
        var currentIndex = sender._currentIndex - 1;
        fileNameTextBox = $get('<%= RadUpload1.ClientID %>' + 'Desc' + currentIndex);
        var inputValue = args.get_fileInputField().value;
        var fileName = inputValue.substring(inputValue.lastIndexOf("\\") + 1);

        fileNameTextBox.value = fileName;
    }

    function addTitle(radUpload, args) {
        var curLiEl = args.get_row();
        var firstInput = curLiEl.getElementsByTagName("input")[0];

        //Create a simple HTML template.
        var table = document.createElement("table");
        table.className = 'AdditionalInputs';

        //A new row for a Title field
        row = table.insertRow(-1);
        cell = row.insertCell(-1);
        var input = CreateInput("Title", "text");
        input.className = "TextField";
        input.id = input.name = radUpload.getID(input.name);
        var label = CreateLabel("Title", input.id);
        cell.appendChild(label);
        cell = row.insertCell(-1);
        cell.appendChild(input);

        //A new row for a Description field
        row = table.insertRow(-1);
        cell = row.insertCell(-1);

        input = CreateInput("Desc", "text");
        input.className = "TextField";
        input.id = input.name = radUpload.getID(input.name);
        label = CreateLabel("Description", input.id);
        //label.innerHTML = firstInput.valueOf;
        cell.appendChild(label);
        cell = row.insertCell(-1);
        cell.appendChild(input);

        //Add a File label in front of the file input
        var fileInputSpan = curLiEl.getElementsByTagName("span")[0];
        var firstNode = curLiEl.childNodes[0];
        label = CreateLabel("File", radUpload.getID());
        curLiEl.insertBefore(label, firstNode);

        curLiEl.insertBefore(table, label);
    }
</script>

1 Answer, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 16 Nov 2011, 10:41 AM
Hi Leroy,

I wasn't able to run your sample code.
My suggestion is to find the text box with jQuery and set the value you want. E.g. you can access the li element that contains the additional fields and the input type='file'.
$telerik.$(args.get_fileInputField()).parents("li:first")

To avoid duplication of the the thread please continue the discussion in only one of them.

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Upload (Obsolete)
Asked by
Mark
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Share this question
or