Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

72
Vistas
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 ?

7 months ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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;
}
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.