...

View Full Version : tweak to this code?



ojoonline
01-20-2006, 03:23 AM
hi,

this is working great... but i now need to include the enabling/disabling of an extra field.

here's a working version-> http://www.textit.com.au/x-testradio2.cfm

I would like to include the sendDate textfield in the 'Schedule for' radio enabling/disabling.

is this possible?



<html>

<head>
<title></title>

<script language="JavaScript" src="console/ts_picker.js">

//Script by Denis Gritcyuk: tspicker@yahoo.com
//Submitted to JavaScript Kit (http://javascriptkit.com)
//Visit http://javascriptkit.com for this script

</script>

<script language="JavaScript" type="text/javascript">
<!--
// better code by Cory Arthus - 11/23/2005 - http://www.coryarthus.com/
function enableByName(strName, f) {
var e = f.elements;
for ( var i = 0; i < e.length; i++ ) {
if ( e[i].type != 'radio' && e[i].name != strName&&e[i].type != 'submit' )
e[i].disabled = true;
else
e[i].disabled = false;
}
}


//-->
</script>

</head>

<body onload="enableByName('messageForm',document.forms[0]);">
<form action="x-testRadio2.cfm" method="post" name="messageForm">
<input id="R1" type="radio" name="sendNow" value="Y" checked='checked' onclick="enableByName('name1',this.form);" />
Now<br />
<br />
<input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName('sendTime',this.form);" >
Schedule for
<select name="sendTime">
<option value="12:00AM">12:00AM</option>
<option value="1:00AM">1:00AM</option>
<option value="2:00AM">2:00AM</option>
<option value="3:00AM">3:00AM</option>
<option value="4:00AM">4:00AM</option>
<option value="5:00AM">5:00AM</option>
<option value="6:00AM">6:00AM</option>
<option value="7:00AM">7:00AM</option>
<option value="8:00AM">8:00AM</option>
<option value="9:00AM">9:00AM</option>
<option value="10:00AM">10:00AM</option>
<option value="11:00AM">11:00AM</option>
<option value="12:00PM">12:00PM</option>
<option value="1:00PM">1:00PM</option>
<option value="2:00PM">2:00PM</option>
<option value="3:00PM">3:00PM</option>
<option value="4:00PM">4:00PM</option>
<option value="5:00PM" selected>5:00PM</option>
<option value="6:00PM">6:00PM</option>
<option value="7:00PM">7:00PM</option>
<option value="8:00PM">8:00PM</option>
<option value="9:00PM">9:00PM</option>
<option value="10:00PM">10:00PM</option>
<option value="11:00PM">11:00PM</option>
</select>
<input type="Text" name="sendDate" size="6" readonly="yes">
<a href="javascript:show_calendar('document.messageForm.sendDate', document.messageForm.sendDate.value);"><img src="console/images/cal.gif" border="0" alt="Click here to pick a date."></a>
<br><br>

<input type="submit" name="Submit" value="Submit">
<br>
</form>
</body>

</html>


thanks,

jo

glenngv
01-20-2006, 04:52 AM
var arrFields = new Array();
arrFields[0] = []; //fields for radio button 1
arrFields[1] = ["sendTime", "sendDate"]; //fields for radio button 2

function enableByName(index, f){
for (var i=0; arrFields.length; i++){
for (var j=0; arrFields[i].length; j++){
f.elements[arrField[i][j]].disabled = (index==i) ? false : true;
}
}
}
...
<input id="R1" type="radio" name="sendNow" value="Y" checked="checked" onclick="enableByName(0, this.form);" />
<label for="R1">Now</label>
<br />
<input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName(1, this.form);" >
<label for="R3">Schedule for</label>
...

ojoonline
01-20-2006, 06:27 AM
hi glenngv,

thank you for the tweak :-)

I have put that code up here -> http://www.textit.com.au/x-testradio4.cfm

unfortunately, nothing seems to enable / disable at all??

thanks,

jo

glenngv
01-23-2006, 04:22 AM
I had a typo.

function enableByName(index, f){
for (var i=0; arrFields.length; i++){
for (var j=0; arrFields[i].length; j++){
f.elements[arrFields[i][j]].disabled = (index==i) ? false : true;
}
}
}
If you see the Javascript Console, you can easily spot the error.
BTW, your onload should look like this:

onload="enableByName(0, document.forms[0]);"
The first parameter is the index position (zero-based) of the selected radio button.

ojoonline
01-23-2006, 04:22 AM
Hi,

I'm actually getting a 'Page done but with errors' for this code below. Any thoughts as to why this is happening?



<head>
<script language="JavaScript" type="text/javascript">
<!--
var arrFields = new Array();
arrFields[0] = []; //fields for radio button 1
arrFields[1] = ["sendTime", "sendDate"]; //fields for radio button 2

function enableByName(index, f){
for (var i=0; arrFields.length; i++){
for (var j=0; arrFields[i].length; j++){
f.elements[arrField[i][j]].disabled = (index==i) ? true : false;
}
}
}
//-->
</script>
</head>


<body onload="enableByName('messageForm',document.forms[0]);">
<form action="x-testRadio2.cfm" method="post" name="messageForm">
<input id="R1" type="radio" name="sendNow" value="Y" checked="checked" onclick="enableByName(0, this.form);" />
<label for="R1">Now</label> <br />
<input id="R3" type="radio" name="sendNow" value="N" onclick="enableByName(1, this.form);" >
<label for="R3">Schedule for</label>
<input type="text" name="sendTime"> / <input type="text" name="sendDate">
<br>
<input type="submit" name="Submit" value="Submit">
<br>
</form>
</body>


thanks :-)

jo

ojoonline
01-23-2006, 04:25 AM
lol. We posted simulataneously :-) thanks for your response. I'll give it a go now... jo

ojoonline
01-23-2006, 04:27 AM
thanks... that works a treat! wonderful stuff :-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum