单击复选框将一个文本框数据复制到另一个文本框中

时间:2013-01-08 10:04:39

标签: javascript html jsp checkbox textbox

    <html>


    Address Line 1
    <input type="text" id="stu_per_add_one" name="stu_pre_add_one" maxlength="40" size="35"/>

    Address Line 2
    <input type="text" id="stu_pre_add_two" name="stu_pre_add_two" maxlength="40" size="35"/>

    Address Line 3
    <input type="text" id="stu_pre_add_three" name="stu_pre_add_three" maxlength="40" size="35"/>

    Village
    <input type="text" id="stu_pre_village" name="stu_pre_village" maxlength="40" size="35"/>

    Taluka
    <input type="text" id="stu_pre_taluka" name="stu_pre_taluka" maxlength="40" size="35" />

    City
    <input type="text" id="stu_pre_city" name="stu_pre_city" maxlength="40" size="35" />

    District
    <input type="text" id="stu_pre_dist" name="stu_pre_dist" maxlength="40" size="35" />

    <input id="sameadd" name="sameadd" type="checkbox" value="Sameadd" onchange="CopyAdd(this);" />&nbsp;&nbsp;&nbsp;
    Check if Permenent Address Same as Present Address

    <script type="text/javascript">
            function CopyAdd(cb) 
            {
                var cb = document.getElementById('sameadd');
                var a1 = document.getElementById('stu_pre_add_one');
                var al1 = document.getElementById('stu_per_add_one');
                var a2 = document.getElementById('stu_pre_add_two');
                var al2 = document.getElementById('stu_per_add_two');
                var a3 = document.getElementById('stu_pre_add_three');
                var al3 = document.getElementById('stu_per_add_three');
                var v1 = document.getElementById('stu_pre_village');
                var vl1 = document.getElementById('stu_per_village');
                var t1 = document.getElementById('stu_pre_taluka');
                var tl1 = document.getElementById('stu_per_taluka');
                var c1 = document.getElementById('stu_pre_city');
                var cl1 = document.getElementById('stu_per_city');
                var d1 = document.getElementById('stu_pre_dist');
                var dl1 = document.getElementById('stu_pre_dist');

                if (cb.checked) 
                {
                    al1.value = a1.value;
                    al2.value = a2.value;
                    al3.value = a3.value;
                    vl1.value = v1.value;
                    tl1.value = t1.value;
                    cl1.value = c1.value;
                    dl1.value = d1.value;

                } 
                else 
                {
                    al1.value = '';
                    al2.value = '';
                    al3.value = '';
                    vl1.value = '';
                    tl1.value = '';
                    cl1.value = '';
                    dl1.value = '';

                }
            }
     </script>


    Address Line 1
    <input type="text" id="stu_per_add_one" name="stu_per_add_one" maxlength="40" size="35"/>

    Address Line 2
    <input type="text" id="stu_per_add_two" name="stu_per_add_two" maxlength="40" size="35"/>

    Address Line 3
    <input type="text" id="stu_per_add_three" name="stu_per_add_three" maxlength="40" size="35"/>

    Village
    <input type="text" id="stu_per_village" name="stu_per_village" maxlength="40" size="35"/>

    Taluka
    <input type="text" id="stu_per_taluka" name="stu_per_taluka" maxlength="40" size="35" />

    City
    <input type="text" id="stu_per_city" name="stu_per_city" maxlength="40" size="35" />

    District
    <input type="text" id="stu_pre_dist" name="stu_pre_dist" maxlength="40" size="35" />

    </html>

请解决它为什么不工作..... 可能是本规范中遗漏的东西...... 此外,我尝试了这个代码然后它不复制任何文本框数据相同... 我想直接为7个文本框做... 我无法正常工作。 我不知道缺少什么。 请有人解决它...... 我正在研究JSP项目...

由于 Jugal

1 个答案:

答案 0 :(得分:2)

看到这个小提琴:http://jsfiddle.net/nc3sH/1/

您有元素的重复ID,并且在元素ID中preper之间的使用混淆...