Connecting Tech Pros Worldwide Forums | Help | Site Map

How to make text box uneditable?

fieryscream's Avatar
Newbie
 
Join Date: Sep 2009
Location: NZ
Posts: 8
#1: Sep 3 '09
I have an address form that user fills out
and whent they click same as above it fills out the postal address
how do i make the postal address non editable once the user clicks the same as above box?

Expand|Select|Wrap|Line Numbers
  1. function sameaddress()
  2. {
  3.     document.getElementById("st1").value=document.getElementById("street1").value;
  4.     document.getElementById("st2").value=document.getElementById("street2").value;
  5.     document.getElementById("st3").value=document.getElementById("street3").value;
  6.     document.getElementById("city2").value=document.getElementById("city").value;
  7.     document.getElementById("country2").value=document.getElementById("country1").value;
  8. }
  9.  
HTML

Expand|Select|Wrap|Line Numbers
  1. <p align="left" class="style1">Physical Address:</p>
  2.     <p align="left" class="style1">Street
  3.       <input name="street1" type="text" value="" size="30" id="street1" />
  4.     </p>
  5.     <p align="left"> <span class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  6.           <input name="street2" size="30" maxlength="15" value="" type="text" id="street2" />
  7.     </span></p>
  8.     <p align="left"> <span class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  9.           <input name="street3" size="30" maxlength="15" value="" type="text" id="street3" />
  10.     </span></p>
  11.     <p align="left" class="style1">City 
  12.       &nbsp;&nbsp;&nbsp;
  13.         <input name="city" size="30" maxlength="15" value="" type="text" id="city" />
  14.     </p>
  15.     <p align="left" class="style1">Country
  16.       <select name="country1" id="country1">
  17.           <option>NZ</option>
  18.           <option>AU</option>
  19.           <option>UK</option>
  20.           <option>US</option>
  21.         </select>
  22.     </p>
  23.     <p align="left" class="style1">Postal Address:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  24.         <label>Same as above
  25.           <input name="abovebox" type="checkbox" onClick="sameaddress()" />
  26.       </label>
  27.     </p>
  28.     <p align="left" class="style1">Street
  29.       <input name="st1" type="text" value="" size="30" id="st1" />
  30.     </p>
  31.     <p align="left"> <span class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  32.           <input name="st2" size="30" maxlength="15" value="" type="text" id="st2" />
  33.     </span></p>
  34.     <p align="left"> <span class="style1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  35.           <input name="st3" size="30" maxlength="15" value="" type="text" id="st3" />
  36.     </span></p>
  37.     <p align="left" class="style1">City 
  38.       &nbsp;&nbsp;&nbsp;
  39.         <input name="city2" size="30" maxlength="15" value="" type="text" id="city2" />
  40.     </p>
  41.     <p align="left" class="style1">Country
  42.       <select name="country2" id="country2">
  43.           <option>NZ</option>
  44.           <option>AU</option>
  45.           <option>UK</option>
  46.           <option>US</option>
  47.         </select>
  48.     </p>

fieryscream's Avatar
Newbie
 
Join Date: Sep 2009
Location: NZ
Posts: 8
#2: Sep 3 '09

re: How to make text box uneditable?


absolute legend if anyone can get it to work!
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#3: Sep 3 '09

re: How to make text box uneditable?


what about setting the disabled property?

besides that a label should not include the input element.
Expand|Select|Wrap|Line Numbers
  1. <label for="inp_id">label text for input field</label>
  2. <input id="inp_id" …>
right alignment can als be achieved by CSS (float: right), no need to use spaces (there are more or less complex layouts available, search for form, css, layout)
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#4: Sep 3 '09

re: How to make text box uneditable?


An example of what Dormilich is talking about:

Expand|Select|Wrap|Line Numbers
  1. function sameaddress()
  2. { document.getElementById("st1").value=document.getElementById("street1").value;
  3.      document.getElementById("st2").value=document.getElementById("street2").value;
  4.   document.getElementById("st3").value=document.getElementById("street3").value;
  5.   document.getElementById("city2").value=document.getElementById("city").value;
  6.   document.getElementById("country2").value=document.getElementById("country1").value;
  7.   document.getElementById("country1").disabled = true;
  8. }
fieryscream's Avatar
Newbie
 
Join Date: Sep 2009
Location: NZ
Posts: 8
#5: Sep 6 '09

re: How to make text box uneditable?


yup cool that was gold!~

how do i make when unchecked then the boxes then become blank again?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,664
#6: Sep 6 '09

re: How to make text box uneditable?


set their value to "".

_________
Reply

Tags
non-editable, same as above