Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!