0

I have a week input

 <input type="week" name="weeks" id="weeks">

I want to be able to select multiple weeks with this input. I tried the "multiple" parameter but it didn't work. Is there any way to do this?

zokanzi
  • 117
  • 3
  • 15

1 Answers1

1

I think you can try this idea:

In your JS:

 var weeks = [] //here store the weeks selected by the user; 
 function handler(e){
    weeks.push(e.target.value)
 }

In your HTML:

 <input type="week" name="week" id="weeks" onchange="handler(event);">

 <div class='weeks'>
         <-- here you can display the selected weeks --!>
 </div>

Show to the user only one input, and when he selects a week you save this week in the weeks array, and clear the week input to allow him to select another week.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
walidum
  • 153
  • 1
  • 9
  • 1
    Please tell how to "Show to the user only one input, and when he selects a week you save this week in the weeks array, and clear the week input to allow him to select another week.". – Aviral Aug 24 '21 at 08:29
  • Good idea but i want the user to see the selected week. Clearing the input doesn't work for me. – zokanzi Aug 24 '21 at 08:31
  • 1
    I edit the response, you can chek if it's ok – walidum Aug 24 '21 at 08:35
  • 1
    Hi @zokani you can show the content of the array weeks to the user :) . – walidum Aug 24 '21 at 08:37