Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One input field, multiple names

Tags:

html

forms

In a HTML form, how can I get two names from one input field? Is it possible through hidden input fields? And how? I tried to make the hidden field value dynamically equal to the non-hidden one (so that they will be equal no matter what the user writes), but I'm sure just that it doesn't work, not whether something like this would work. Here was suggested that something similar should be possible. My problem should be in the value attribute - I tried different values, but I didn't manage to bind it to the foo value.

<input name="foo" id="foo" type="text" value="foobar" />
<input type="hidden" name="bar" id="bar" value=foo />

I would prefer to solve it without Java Script.

I'd like to use both attributes for different websites, which use different names for the same property (the same for our purpose, the role is slightly different, but format and value is the same).

like image 221
Pavel V. Avatar asked Jul 18 '26 16:07

Pavel V.


1 Answers

It is not possible without JavaScript. Hidden input fields are just static data, as far as HTML is concerned; they are not affected by user input in any way. Similarly, when user input changes the value of a field, there is no way in HTML to specify that this would also change another field.

The statement “I’d like to use both attributes for different websites, which use different names for the same property” seems to suggest that the form data is to be submitted to one of two or more servers depending on something. Although this is technically possible without JavaScript if certain HTML5 features are used, their browser support is limited. The feasible options are: 1) Use different forms, 2) Use JavaScript, 3) Use a simple server-side mediator that passes the data forward to one or more server-side handlers depending on some field(s) in the data.

like image 122
Jukka K. Korpela Avatar answered Jul 20 '26 06:07

Jukka K. Korpela