A
A
Albert2021-06-29 20:58:14
PHP
Albert, 2021-06-29 20:58:14

How to get input value if there are two of them and they change?

Hello.

There are 2 inputs and select. for example

<select class='form-control' name='select'>
      <option value='1'>Открыть первое текстовое поле</option> 
      <option value='2'>Открыть второе текстовое поле</option>
</select>

<input type='text' name='input1' id="input1" class='' placeholder='Введите почту'>
<input type='text' name='input2' id="input2" class='' placeholder='Введите номер телефона style='display:none'>


By choosing a select, the corresponding input appears. Inputs are distinguished by a placeholder and a mask. Therefore, I had to make 2 different ones and simply hide the second one through display none.

Everything is working. Now I want to transfer the received value through php to the database. But I can’t figure out how to put the value of the input that I chose into 1 cell.

Track the input that is visible and put the resulting value in some kind of input hidden or what?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-06-29
@delphinpro

No need to shove heterogeneous data into one cell.
Make two fields tel and email, both nullable and fill in the data that came.
But if you still want to, then along with both inputs you will receive a select value, on the basis of which you can make a choice which of the two input values ​​to choose to save in the database.

S
Sergey, 2021-06-29
@sslion

apparently these inputs are "changing" through js, so in the function, save the value of the active input to a variable, and pass this value to the php handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question