biswaranjan.rath said on 28/04/2006 3:54 PM AEST:
Hi,
I've few checkboxes in different rows. After selecting appropriate
values, the user should click a button. I wanted to convert those
checkbox values to non-editable(or non-editable textboxes), so that
user cannot change the value again after the needed functionality(this
is in java script) completes. So my problem is that how should i
manipulate the page through java script to set the field noneditable.
Please suggest.
Set the disabled attribute of any unchecked radios to true, then the
user can't select any other option.
If scripting is disabled/not available, it won't work. If there's a
reset button, the user can reset the form and clear the selections
anyway. There are probably other ways around it, don't rely on it
working for anything important.
Play with this:
<script type="text/javascript">
function fixSelections(rGroup)
{
var i = rGroup.length;
var j = i;
var oneChecked = false;
// Check that one has been selected
while (j-- && !oneChecked){
oneChecked = rGroup[j].checked;
}
// If one hasn't been selected, ask user to select one
if (!oneChecked) {
alert('Please check an option');
return;
}
// If one has been selected, disable the rest
while (i--){
rGroup[i].disabled = !rGroup[i].checked;
}
}
function enableRadios(rGroup)
{
var i = rGroup.length;
while (i--){
rGroup[i].disabled = false;
}
}
</script>
<form action=""><div>
<input type="radio" name="r1">button 1<br>
<input type="radio" name="r1">button 2<br>
<input type="radio" name="r1">button 3<br>
<input type="radio" name="r1">button 4<br>
<input type="button" value="Fix selection"
onclick="fixSelections(this.form.r1);"><br>
<input type="reset" onclick="enableRadios(this.form.r1);">
</div></form>
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>