Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
js mulipe-input does not pass all values?

i have problem plz help when i click on button it pass just an array(speaker) without any other parameters(sub,compose) i try to sent just the parameter (sub,compose) but its does not pass, i need when i click button pass all(array(speaker) and (sub,compose) this is hrml code

<multi-input>
        <input list="speakers">
      <datalist id="speakers">
        <option value="Banquo"></option>
        <option value="Bishop Stokesly of London"></option>
        <option value="Caesar’s Second Watchman"></option>
        <option value="Celia"></option>
        <option value="Cleopatra"></option>
        <option value="Dogberry"></option>
        <option value="Falstaff"></option>
        <option value="First Servant"></option>
        <option value="Hamlet"></option>
        <option value="Juliet"></option>
        <option value="Macbeth"></option>
      </datalist>
    </multi-input>
                <div class="form-group">
                  <input class="form-control" placeholder="Subject:" id="sub">
                </div>
                <div class="form-group">
                    <textarea id="compose" class="form-control" style="height: 300px">
     <button type="submit" name="submit" class="btn btn-primary" id="get"><i class="far fa-envelope"></i> Send</button>

and this is js code

const getButton = document.getElementById('get');
var sub = document.getElementById('sub').value;
var compose= document.getElementById('compose').value;
const multiInput = document.querySelector('multi-input'); 
getButton.onclick = () => {
var src="sent.php?sub="+multiInput.getValues()+'&sub='+sub+'&compose='+compose+'';
window.location.href=src;
}

just the array (multi-input) pass the other not whay ?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To specify your array as URL parameters, you need to add "[]" before "=" sign. In that way php recognizes it as array. Otherwise the value will be just a string.

/*------ Change This -------*/
var src="sent.php?sub="+multiInput.getValues()+'&sub='+sub+'&compose='+compose+'';
window.location.href=src;

/*----- To this -------*/
var src="sent.php?sub[]="+multiInput.getValues()+'&sub='+sub+'&compose='+compose+'';
window.location.href=src;

Secondly, since your 'onclick' function does not update the values of variables you've defined above; it just not get the latest value of them. To solve this issue moving variables inside the function is enough.

const getButton = document.getElementById('get');
const multiInput = document.querySelector('multi-input'); 
getButton.onclick = () => {

/*----- Define them in here -------*/
var sub = document.getElementById('sub').value;
var compose= document.getElementById('compose').value;

var src="sent.php?sub="+multiInput.getValues()+'&sub='+sub+'&compose='+compose+'';
window.location.href=src;
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda