How to make multiple forms with shared fields without using javascript?
<input type=text name开发者_开发百科=username />
<form action="/users">
... some fields ...
</form>
<form action="/admins">
... some another fields ...
</form>
It is no necessary to have the input tag inside the form: an input can be associated with its form using its form
attribute.
It would be nice if forms could share inputs, but i haven't heard of this. Maybe we should ask W3C to introduce this in HTML6?
UPDATE: One workaround would be to have a single form with multiple "Submit" buttons, using <input type="submit" name="..." value="..." />
or <button type="submit" name="..." value="...">...</button>
elements, so that all the fields get submitted when any button is pressed, and the server side can then check which button was pressed.
I don't think this is possible. For your purposes, the input tag must be inside a form tag. Furthermore, you can't nest different form tags inside each other, so there is no way to solve your problem without using JavaScript.
If you want to use JavaScript, you could provide both forms with an editfield with the same name and write JS to sync the both.
In jQuery, you would do it like this:
$('input[name="username"]').change(function() {
$('input[name="username"]').val($(this).val());
});
(this is just off the top of my head...you could still do it more pretty)
精彩评论