如何记住输入表单值?

时间:2010-10-27 15:08:22

标签: javascript forms

我正在尝试创建2个表单,用户可以通过单击form1和formt2来选择。

当用户在form1和form2之间选择时。我希望form2记住form1的值,并传递所选表单的值以供提交

如何以最简单的方式完成?

由于

1 个答案:

答案 0 :(得分:0)

如何为相似的条目使用相同的输入?

您可以使用CSS类隐藏您不想看到的元素/标签。

<script type="text/javascript">
$(document).ready(function() {
    $('.form-select').change(function() {
        // changes the class of our form
        var setClass = "mode" + $('input[name=whichForm]:radio:checked').val();
        $('#theForm').attr('class',setClass);
    });
});
</script>

<style type="text/css">
    #theForm fieldset { display: inline; }       // just a visual preference
    #theForm .business { color: blue; }          // color-coding
    #theForm .personal { color: green; }         // more color-coding
    #theForm.mode1 .business { display: none; }  // hides .business items when not needed
    #theForm.mode2 .personal { display: none; }  // hides .personal items when not needed
</style>

<form id="theForm" class="mode3" action="take-form.php">
    <fieldset>
        <legend> Information </legend>
        <input type="radio" id="whichForm-1" class="form-select" name="whichForm" value="1"><label for="whichForm-1">Personal</label>
        <input type="radio" id="whichForm-2" class="form-select" name="whichForm" value="2"><label for="whichForm-2">Business</label>
        <input type="radio" id="whichForm-3" class="form-select" name="whichForm" value="3"><label for="whichForm-3">Show All (Debug)</label>
        <hr>
        <input type="text" id="name" name="name">
        <label for="name">
                <span class="personal">Your</span>
                <span class="business">Business</span>
                <span> Name</span>
        </label>
        <br>
        <input type="text" id="address" name="address">
        <label for="address">
            <span class="personal">Home</span>
            <span class="business">Office</span>
            <span> Address</span>
        </label>
    </fieldset>
</form>
相关问题