Binding a select and text as one on a form

Hello there! I have this piece of code

<form>	
	Me:	<select name="drink" >
			<option  value="0">new drink</option>
			<option  value="1">old drink</option>
		</select>
		<input type="text" value="" name="number" >
</form>

it permits me get an order via $_POST['drink'] and $_POST['number'], is it possible to get this two HTML fields as one, that is assessing their value through a single variable instead of 2.

You could give them the same name, but pass it through an array. Like, each could have the following name

name=“thingy

Then that could be assessed through the same name, but through PHP indexes.

Or you could simply concatenate the values when you read them in your script

Use a combobox instead.

<form>	
Me: <input type="text" value="" name="number" list="num">
<datalist id="num">
<option  value="0">new drink</option>
<option  value="1">old drink</option>
</datalist>
</form>

Hello Felgall, how do i assess my submitted values I use php as backend. The user chooses these two values dynamically (hence no limit to the number of articles chosen) so I think your script will be of much help to me.

simply test if the value entered is valid based on what you want to allow them to enter. Obviously the values in the datalist need to be within that range as well.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.