One input field, multiple names

14,076

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.

Share:
14,076

Related videos on Youtube

Pavel V.
Author by

Pavel V.

I'm a beginning expert on computer applications in archaeology - especially GIS (ArcGIS, QGIS) and databases (PostgreSQL, MySQL), but I also dabble in making websites (html/css and I learn php and JavaScript). He on SO, I'm sort of a "noob pioneer", asking stupid questions that other noobs wanted to know but are afraid to ask themselves. I hope I'll be able to share information about my native language here on SE.

Updated on September 16, 2022

Comments

  • Pavel V.
    Pavel V. over 1 year

    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).