...

View Full Version : Disable a radio button on form submit



deepthiz
02-27-2012, 03:39 PM
Hello all,

I have 2 radio buttons
update bsc value
update mnr value

when user selects update mnr value, two more radio buttons should appear.
I have mnr value
I do not have mnr value.

On selecing I do not have mnr value im submitting the form and enabling the user to select values from dropdown. ( not shown in the code as it is a coldfusion code.).

On submit I am not able to still keep the 'but2', and 'my_select3' elements disabled.

Please advice. I have been working on this since quite sometime.

<script language="JavaScript">
function makeChoice() {
var obj1 = document.getElementById('box1')
var obj2 = document.getElementById('box2')
if (document.getElementById('but1').checked) {
obj2.setAttribute('readOnly','readonly');
obj1.removeAttribute('readOnly');
document.getElementById('but1').disabled=true;
document.getElementById('but2').disabled=true;
}
else if (document.getElementById('but2').checked) {

obj1.setAttribute('readOnly','readonly');
obj2.removeAttribute('readOnly');
document.getElementById('but2').disabled=true;
document.getElementById('but1').disabled=true;

}

}
</script>

<script type="text/javascript">
function showSelect() {

if (document.getElementById('but2').checked)
{
document.getElementById('but2').disabled=true;
}

}
</script>

<script type="text/javascript">
function showSelect1() {
if (document.getElementById('but2').checked)
{
document.myform.submit();
document.getElementById('but2').disabled=true
document.getElementById('my_select3').disabled=true
}

}
</script>


<td><input type="radio" id="but1" name="vals" onclick="makeChoice()"></td>
<td>Update BSC Value </td>

<tr>
<td><input type="radio" id="but2" name="vals" onclick="makeChoice();showSelect();" ></td>
<td>Update MNR Value </td>

<td> <input id="my_select1" class="show" type="radio" name="my_select1" onclick="this.myform['my_select1'].disabled=true"></td>

<td> I have a Position Number </td>


<td><input id="my_select3" class="show" type="radio" name="my_select3" onclick="showSelect1();"></td>

<td> I do not have a Position Number </td>

Philip M
02-27-2012, 04:05 PM
document.getElementById('but2').disabled=true
document.getElementById('my_select3').disabled=true
document.myform.submit();


Obviously for us to overtake them has been a massive undertaking. - Football manager, ITV 1

deepthiz
02-27-2012, 05:41 PM
I tried this too, it gets disabled before the form is submitted for a second and when the page reloads the radio buttons have no selection. (they are no disabled). Please advice

Philip M
02-27-2012, 06:38 PM
I tried this too, it gets disabled before the form is submitted for a second and when the page reloads the radio buttons have no selection. (they are no disabled). Please advice

When the page reloads it starts over just as though it as loading for the first time. If you want to persist the state of some element you must use a cookie. But why do you want to do that? Are you trying to prevent the user from submitting the form a second time?

deepthiz
02-27-2012, 06:41 PM
Can you please give me an example of this....so that I can use it in my JS

Philip M
02-27-2012, 07:06 PM
Try using the search feature of this forum. Cookies have been covered a zillion times - including today at http://www.codingforums.com/showthread.php?t=252750



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum