Menu
Ive searched and havent found anything that I could use for what I am looking to do.
Basically I have two address parts on my form, I need something so that clicking a “same as” checkbox, the second address form becomes disabled and users cant input anything.
Problem is I need to disable some text boxes, another checkbox and three selects… but I would like when you click on the checkbox saying its “same as” — it will pop the values into the form, and THEN disable it, that way you see values. How can I do this?
*scratching head
PayPal reward??
[CODE]<script type="text/javascript">
function sameAs(){
document.form.textfield3.disabled = "true";
document.form.textfield4.disabled = "true";
var textfield1 = document.form.textfield1.value;
var textfield2 = document.form.textfield2.value;
document.form.textfield3.value = textfield1;
document.form.textfield4.value = textfield2;
}
</script>
</head>
<body>
<form name="form" method="post" action="">
<p>
<input name="textfield1" type="text" id="textfield1">
</p>
<p>
<input type="text" name="textfield2">
</p>
<p>
<input type="checkbox" name="checkbox" value="checkbox" onChange="sameAs()">
Same As Above</p>
<p>
<input id="textfield3" type="text" name="textfield3" title="name2">
</p>
<p>
<input name="textfield4" type="text" id="textfield4">
</p>
</form>
</body>
</html>
[/CODE]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var v=new Array()//pairs boxname/value
v[0]=['box1name','123'];
v[1]=['box2name','456'];
v[2]=['box3name','789'];
//and so on
function dis(f,c){
if(c.checked){
for(var i=0;i<v.length;i++){
subdis(f,v[i][0],v[i][1],true)
}
}
else{
for(var i=0;i<v.length;i++){
subdis(f,v[i][0],'',false)
}
}
}
function subdis(f,o,v,d){
f.elements[o].value=v;
f.elements[o].disabled=d;
}
</script>
</head>
<body>
<form>
<input type="checkbox" value="same as" onclick="dis(this.form,this)">
<br>
<br>
<input name="box1name" type="text"><br>
<input name="box2name" type="text"><br>
<input name="box3name" type="text"><br>
</form>
</body>
</html>
[/code]
<i>
</i><HTML>
<Head>
<Script Language=JavaScript>
<i> </i>function xferData(isForm,isState){
<i> </i> if (isState)
<i> </i> {
<i> </i> isForm.shipAddress.value = isForm.billAddress.value;
<i> </i> isForm.shipCity.value = isForm.billCity.value
<i> </i> isForm.shipState.selectedIndex = isForm.billState.selectedIndex;
<i> </i> isForm.shipZip.selectedIndex = isForm.billZip.selectedIndex;
<i> </i> isForm.shipBox.checked = isForm.billBox.checked;
<i> </i> isForm.shipAddress.disabled = true;
<i> </i> isForm.shipCity.disabled = true;
<i> </i> isForm.shipState.disabled = true;
<i> </i> isForm.shipZip.disabled = true;
<i> </i> isForm.shipBox.disabled = true;
<i> </i> }
<i> </i> else {
<i> </i> isForm.shipAddress.value = "";
<i> </i> isForm.shipCity.value = "";
<i> </i> isForm.shipState.selectedIndex = 0;
<i> </i> isForm.shipZip.selectedIndex = 0;
<i> </i> isForm.shipBox.checked = false;
<i> </i> isForm.shipAddress.disabled = false;
<i> </i> isForm.shipCity.disabled = false;
<i> </i> isForm.shipState.disabled = false;
<i> </i> isForm.shipZip.disabled = false;
<i> </i> isForm.shipBox.disabled = false;
<i> </i> }
<i> </i>}
</Script>
</Head>
<Body>
<Form name='Form1'>
Bill To:<br>
Address: <input type=text size=15 name='billAddress' ><br>
City: <input type=text size=15 name='billCity'><br>
State:
<Select name='billState'>
<option selected value=''> Make a Selection</option>
<option value='California'> California </option>
<option value='Texa'> Texas </option>
</Select>
<br>
Zip: <Select name='billZip'>
<option selected value='0'>Make a Selection</option>
<option value='12345'> 12345 </option>
<option value='14523'> 14523 </option>
</Select><br>
<br>
Some box: <input type=checkbox name='billBox'>
<br>
<br>
Shipping Address Same As Billing Address? <input type=checkbox onclick="xferData(this.form,this.checked)">
<br>
<br>
Ship To:<br>
Address: <input type=text size=15 name='shipAddress'><br>
City: <input type=text size=15 name='shipCity'><br>
State:
<Select name='shipState'>
<option selected value=''>Make a Selection</option>
<option value='California'> California </option>
<option value='Texa'> Texas </option>
</Select><br>
Zip: <Select name='shipZip'>
<option selected value='0'>Make a Selection</option>
<option value='12345'> 12345 </option>
<option value='14523'> 14523 </option>
</Select>
<br>
Some box: <input type=checkbox name='shipBox'>
</Form>
</Body>
</HTML>
Something like this?:
[code=php]
[/QUOTE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var v=new Array()//pairs boxname/value
v[0]=['box1name','123'];
v[1]=['box2name','456'];
v[2]=['box3name','789'];
//and so on
function dis(f,c){
if(c.checked){
for(var i=0;i<v.length;i++){
subdis(f,v[i][0],v[i][1],true)
}
}
else{
for(var i=0;i<v.length;i++){
subdis(f,v[i][0],'',false)
}
}
}
function subdis(f,o,v,d){
f.elements[o].value=v;
f.elements[o].disabled=d;
}
</script>
</head>
<body>
<form>
<input type="checkbox" value="same as" onclick="dis(this.form,this)">
<br>
<br>
<input name="box1name" type="text"><br>
<input name="box2name" type="text"><br>
<input name="box3name" type="text"><br>
</form>
</body>
</html>
[/code]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var s;
var names=[];
function autofill(isC){
var j=0;
var secObj = document.getElementById('second')
var cloned = document.getElementById('first').cloneNode(true);
var ele = cloned.getElementsByTagName('*');
for (var i=0;i<ele.length;i++){
if(ele[i].tagName.toLowerCase()=='select'){
ele[i].selectedIndex=s;
}
if(ele[i].name){
ele[i].name = names[j];
ele[i].disabled=(isC)?true:false;
j++}
}
cloned.setAttribute('id','second');
document.getElementById('first').parentNode.replaceChild(cloned,secObj)
}
onload=function(){
var ele = document.getElementById('second').getElementsByTagName('*')
for (var i=0;i<ele.length;i++){
if(ele[i].name){names[names.length]=ele[i].name}
}
}
</script>
</head>
<body>
<form>
<div id="first">
<input name="txt1" type="text">
<br>
<select name="sel1" onchange="s=this.selectedIndex">
<option value="1">1</option>
<option value="12">12</option>
<option value="123">123</option>
</select>
<br>
<input name="che1" type="checkbox">
</div>
<hr>
<input type="checkbox" onclick="autofill(this.checked)"> wanna fill below with the same values?
<hr>
<div id="second">
<input name="txt2" type="text">
<br>
<select name="sel2">
<option value="1">1</option>
<option value="12">12</option>
<option value="123">123</option>
</select>
<br>
<input name="che2" type="checkbox">
</div>
</form>
</body>
</html>
[/code]
0.1.9 — BETA 6.16