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

136
Views
Display the selected of a Drop down list (javascript or jquery)

I want to create a form where user have two option for image upload, Either passport, an identity card, or a driver's license, but I want when the user chooses a passport box passport, if the selection of an identity card or a driver's license, two back and front

<form action="">

  <select >
    <option >PASSPORT</option>
    <option >ID CARD</option>
    <option >DRIVER LICENSE</option>
   </select><BR><BR>

  <input type="file" id="myFile" name="PASSPORT"><BR><BR>
  
  <input type="file" id="myFile" name="FRONT ID"><BR><BR>
    
  <input type="file" id="myFile" name="BACK ID"><BR><BR>
  
  <input type="file" id="myFile" name="BACK DRIVER LICENSE"><BR><BR>
  
  <input type="file" id="myFile" name="BACK DRIVER LICENSE"><BR><BR> 

  <input type="submit">  
  
</form>

Example:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is one way of doing it:

(document.querySelector("select").onchange=ev=>{
  document.querySelectorAll("input[type=file]").forEach(e=>{
    e.style.display=ev.target.value.toLowerCase().replaceAll(" ","")===e.className
      ? "block"
      : "none";
   })
})({target:{value:"passport"}});
input[type=file] {margin:10px 0px}
<form action="">
<select >
<option >PASSPORT</option>
<option >ID CARD</option>
<option >DRIVER LICENSE</option>
</select><BR><BR>
  <input type="file" class="passport" name="PASSPORT">  
  <input type="file" class="idcard"   name="FRONT ID">    
  <input type="file" class="idcard" name="BACK ID">  
  <input type="file" class="driverlicense" name="FRONT DRIVER LICENSE">  
  <input type="file" class="driverlicense" name="BACK DRIVER LICENSE">
  <input type="submit">  
</form>

I replaced your invalid id attributes with a class attribute and attached an event listener on the select element. As soon as the event is fired, the value of the select box is used to the style.display attribute of the input elements to either "block" or "none".

By putting the whole function definition in parentheses () and appending the argument ({target:{value:"passport"}}) after it I effectively simulate the firing of an event with a fake "event object"-argument containing a single attribute/sub-attribute: target.value == "passport". This will make the first input group visible while hiding all the others.

about 4 years ago · Juan Pablo Isaza 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!