0

I have a form in which I have a permanent address and correspondence address.
I want the user to enter the permanent address first and then give a checkbox stating if the correspondence address is the same as permanent address. I was able to fill the text boxes with javascript but not able to do it in selection i.e dropdown. How can I do that?

My code for form is:

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

Is there a better way to assign this duplication of similar fields in form on checking the checkbox and I also want the fields to clear on deselecting the checkbox.

j0k
  • 22,600
  • 28
  • 79
  • 90
Badrinath
  • 94
  • 1
  • 12

2 Answers2

0
<select required>
<option>PERMANENT & CORRESPONDENT</option>
<option>RESPECTIVELY</option>
</select>

use onchange event for dropdown, like this,

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

and then get the value of the selected option and perform action accordingly.

0

Here is the function to fill the value,

<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

}

}

  • fine with ur ans but problem is that text fields are populated while drop-down selection has no effect! i want to do same on drop-down selection as if India is selected then in second address India should come and so on.... – Badrinath Jun 04 '13 at 08:24