Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
How to get input value if it is not in html

Inside the code, I create an input element with the file type. I don't add it to the tree. I want to get the value of this input after the user adds it to the file. There is one, but I do not need to add this input to the HTML template.

                    <p-splitButton
                        label="Add document"
                        icon="pi pi-plus"
                        (onClick)="openAddDocument()"
                        [model]="addDocumentButtonMenuItems"
                        styleClass="p-button-help"
                    ></p-splitButton>

public readonly addDocumentButtonMenuItems = [
    {
        label: 'Dowload document', icon: 'pi pi-upload', command: () => {
            this.uploadFile();
        },
    },
];

public uploadFile(): void {
        const input = document.createElement('input');
        input.type = 'file';
        input.click();
    }

How to get value input?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

to get file value of an input file you can use myinput.files[0];after a change event on input

but be careful in modern browser you can't open file dialog from script without a user action (click for sample)

js:14 File chooser dialog can only be shown with a user activation.

in the following link you will found a solution to open a file dialog with native js How to open a file / browse dialog using javascript?

you can bind onChange event of input file to get the chosen file

var fileInput = document.getElementById('theFile');
       fileInput.addEventListener('change', function() {
        var selectedFile = document.getElementById('theFile').files[0];
        console.log(selectedFile.name);
       }); 

function performClick(elemId) {
       var elem = document.getElementById(elemId);
       if(elem && document.createEvent) {
          var evt = document.createEvent("MouseEvents");
          evt.initEvent("click", true, false);
          elem.dispatchEvent(evt);
       }
    }
    
   var fileInput = document.getElementById('theFile');
   fileInput.addEventListener('change', function() {
    var selectedFile = document.getElementById('theFile').files[0];
    console.log(selectedFile.name);
   }); 
    <a href="#" onclick="performClick('theFile');">Open file dialog</a>
    <input type="file" id="theFile" />

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda