0

我有一个表格,其中有一个永久地址和通讯地址。
我希望用户先输入永久地址,然后给出一个复选框,说明通信地址是否与永久地址相同。我能够用 javascript 填充文本框,但不能在选择中完成,即下拉。我怎样才能做到这一点?

我的表单代码是:

<form action="" name="form1" >
    <fieldset>
        PERMANENT ADDRESS:<br />
        <br/> 
        HOUSE/DOOR<input type="text" name="hno1" placeholder="HOUSE/DOOR NUM" required><br/>
        STREET<input type="text" name="street1" placeholder="STREET" required><br/>
        CITY<input type="text" name="city1" placeholder="CITY" required><br/>
        DISTRICT<input type="text" name="district1" placeholder="DISTRICT" required>    <br/>
        STATE<select required name="state1">
                <option>ANDHRA PRADESH</option>
                <option>KARNATAKA</option>
            </select><br />
        COUNTRY<select name="country1" required>
                    <option>INDIA</option>
                    <option>USA</option>
                </select><br />
        PIN<input type="text" name="pin1" placeholder="PIN" required><br/><br />
        CORRESPONDENT ADDRESS:<br />
        <label for="adress same">Same as PERMANENT ADDRESS </label>
        <input name="copy" type="checkbox" onclick="data_copy()"> <br />
        <!--<select required>
        <option>PERMANENT & CORRESPONDENT</option>
        <option>RESPECTIVELY</option>
        </select>-->
        <br/> 
        HOUSE/DOOR <input type="text" name="hno11" placeholder="HOUSE/DOOR NUM"     required><br/>
        STREET<input type="text" name="street11" placeholder="STREET" required><br/>
        CITY<input type="text" name="city11" placeholder="CITY" required><br/>
        DISTRICT<input type="text" name="district11" placeholder="DISTRICT" required>    <br/>
        STATE<select name="state11" required>
                <option>ANDHRA PRADESH</option>
                <option>KARNATAKA</option>
            </select><br/>
        COUNTRY<select name="country11" required>
                    <option>INDIA</option>
                    <option>USA</option>
                </select><br/>
        PIN<input type="text" name="pin11" placeholder="PIN" required><br/><br />
    </fieldset>
</form>

有没有更好的方法可以在选中复选框时在表单中分配这种重复的类似字段,我还希望在取消选中复选框时清除这些字段。

4

2 回答 2

0

这是填充值的函数,

<script type="text/javascript">
function data_copy(str){
if(str=='1'){   // if this the case where both the addresses will be same
   document.form1.hno11.value = document.form1.hno1.value;
   document.form1.street11.value = document.form1.street1.value;
   //.....
   //... so on.. add fields this ways

}

}

于 2013-06-04T04:19:45.063 回答
0
<select required>
<option>PERMANENT & CORRESPONDENT</option>
<option>RESPECTIVELY</option>
</select>

使用onchange事件进行下拉,像这样,

<select required onChange="data_copy(this.value)">
<option value="1">PERMANENT & CORRESPONDENT</option>
<option value="2">RESPECTIVELY</option>
</select>

然后获取所选选项的值并相应地执行操作。

于 2013-06-03T07:13:29.053 回答