Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - Input values on click empty. Can someone explain why?

I am trying to get inputs value but something is wrong. No error, just an empty value on click. Please see the code below. Could someone explain what is wrong?

let tipController = (() => {
  let DOMstring = {
    inputAmount: "#bill_amount",
    inputService: '#service_option',
    inputPeople: '#people'
  };
  return {
    getInput: () => {
      return {
        amount: parseInt(document.querySelector(DOMstring.inputAmount).value),
        service: document.querySelector(DOMstring.inputService).value,
        people: document.querySelector(DOMstring.inputPeople).value,
      }
    }
  })();

// APP CONTROLLER
let appCtrl = ((tipCtrl) => {

  let data = tipCtrl.getInput();
  let test = () => {
    console.log(data.amount);
    console.log(data.service);
    console.log(data.people);
  };

  document.querySelector('.submit').addEventListener('click', test);

})(tipController);
<input id="bill_amount" class="input" type="text" name="bill_amount">
<select class="input" id="service_option">
  <option value="">-- Pick an option --</option>
  <option value="exellent">Exellent</option>
  <option value="good">Good</option>
  <option value="ok">Ok</option>
  <option value="bad">Bad</option>
</select>
<input class="input" type="text" name='people' id='people' placeholder="Number of people">
<button type='submit' class='submit'>Calculate</button>
question from:https://stackoverflow.com/questions/65895466/input-values-on-click-empty-can-someone-explain-why

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...