1

I'm working on my first project and I'm stuck with something. I created input values for my alarm, but I'm stuck with how to use the function to correlate it to the user’s selected values. I want to do something like,
let selectedHour = hour options from the info in the function.value or something and do that for mins and seconds of course.. I just don't know how. Thanks everyone.

This is the function I created to show alarm time selections:

function alarmMenu(){

  let ahours = document.querySelector("#alarmhrs)
  let hrs = 12
  for (i=0; i <= hrs; i++) {
    ahours.options[ahours.options.length] = new Option( i <      10 ? "0" + i : i, i);
  }
  let amins = document.querySelector("#alarmmins");
  let min = 59;
  for (i=0; i <= min; i++) {
    amins.options[amins.options.length] = new Option(i < 10 ? "0" + i : i, i);
  }
  let asecs = document.querySelector("#alarmsecs");
  let sec = 59;
  for (i=0; i <= sec; i++) {
     asecs.options[asecs.options.length] = new Option(i < 10 ? "0" + i : i, i);
  }
 }
alarmMenu();
Claudia V.
  • 19
  • 5
  • Possible duplicate of [How do I get the value of text input field using JavaScript?](https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript) – mikey Oct 17 '19 at 06:16
  • Did not understand your question, please clarify – codemirror Oct 17 '19 at 06:17

1 Answers1

1

If I understood you correctly, you want

let hrs = ahours.value;
let min = amins.value;
let sec = asecs.value;

This will set the value of each to the value of the input field.

MiK
  • 918
  • 4
  • 16
  • MiK, that’s correct. From my understanding though, the ahour, amins, asecs are not global variables. My confusion is on how would I create the variable hrs, min, and sec outside of the alarmMenu function. I want to create a new property for the alarm clock with let hrs = ahours.value etc – Claudia V. Oct 17 '19 at 13:08
  • 1
    Between your – MiK Oct 18 '19 at 06:29