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
160 views
in Technique[技术] by (71.8m points)

api - How to get input value from each input ordered by button using javascript?

I want get userID value for each form separately using javascript api.

I tried :

     <form >
     <input  list="browsers" id="${childSnapshot.val().orderid}" >
     <datalist id="browsers">
       <option value="Order Pending">
       <option value="Order Confirmed">
       <option value="Order Shipped">
       <option value="Order Delivered">
     </datalist>
   </form>
   <input id="${childSnapshot.val().orderid}" value="${childSnapshot.val().userID}"
   <button id="${childSnapshot.val().orderid}"  onclick="reply_click(this.id)" style="padding:1px">Update</button>
       

function reply_click(clicked_id){
  let valueitem = document.getElementById(clicked_id).value;
  var orderid = clicked_id;
  console.log(orderid+valueitem)
}

The result i'm getting Order id and the option value, but userID its not coming how to fix it ?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Try the following demonstrative snippet:

const button = document.getElementById('button');

const onClickHandler = (e) => {
  const orderID = e.target.dataset.orderId;
  const userID = document.getElementById(orderID).value;
  console.log(userID + ' ' + orderID);
}

button.addEventListener('click', onClickHandler);
<form>
  <input id="list" list="browsers">
  
  <datalist id="browsers">
    <option value="Order Pending">
    <option value="Order Confirmed">
    <option value="Order Shipped">
    <option value="Order Delivered">
  </datalist>
  
  <input id="${childSnapshot.val().orderid}" value="${childSnapshot.val().userID}"></input>

  <button id="button" type="button" style="padding: 1px" data-order-id="${childSnapshot.val().orderid}">Update</button>
</form>

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

...