search

Home  >  Q&A  >  body text

Get the value of the text box based on its id VUEjs method

I have two text boxes, both text boxes have values.

But I want to get the value of a text box based on the id number I want to enter.

If I enter 1 it should show the value of textbox 1.

This is what I tried and now it shows the data in both text boxes.

template:

<input  v-model="textdata1" id="1" type="text" placeholder="i am id1, show my value">

<input v-model="textdata2" id="2" type="text" placeholder="i am id2, show my value">

<input v-model="searchid"  type="text" placeholder="which ids data you want, 1 or 2 ">

<button  @click="getvalue">RECEIVE</button>

<div>show value of id 1or2 here: {{id1data}}</div>

VUEJS:

rrr
P粉002023326P粉002023326272 days ago428

reply all(2)I'll reply

  • P粉706038741

    P粉7060387412024-03-27 13:14:36

    This is one method. You can create a pair of data values ​​for each input.

    sssccc
    
    
    
    

    For brevity and organization, you can also use reactive() purpose.

    reply
    0
  • P粉176151589

    P粉1761515892024-03-27 10:50:14

    If you insist on using ID, you can use the following method:

    sssccc
    
    
    
    

    reply
    0
  • Cancelreply