Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2012, 11:26 AM   PM User | #1
Razzy
New Coder

 
Join Date: Jun 2012
Posts: 41
Thanks: 14
Thanked 1 Time in 1 Post
Razzy is an unknown quantity at this point
textbox disabled if another radio button selected

hey people, im not sure whether i have posted this on the right place because im not sure whether this problem will be solved through javascript or html, but i have this small problem...i have four radio buttons, with each radio button linked with a textbox. initially all four textbox should be disabled until one of the radio button is selected. The textbox that is linked to the radio button should be enabled. however if another radio button is selected, then the textbox that is already enabled should be disabled again, and the textbox to which the newly selected radio button should be enabled

would really appreciate it if someone could help

i have made a start on it.the coding is as follows....

Code:
<input type="radio"  name="test"  onclick="chickFill1.disabled=false"/>in KG:	<input type="text" id="chickFill1" size="2" value="" disabled="disabled"/>
    <br/>
    <br/>
    <input type="radio" name="test" onclick="chickFill2.disabled=false"/>in lbs:	<input type="text" id="chickFill2" size="2" value="" disabled="disabled"/>
     <br/>
    <br/>
    <input type="radio" name="test" onclick="chickFill3.disabled=false"/>in money:	£<input type="text" id="chickFill3" size="4" value="00.00" disabled="disabled"/>
     <br/>
    <br/>
    <input type="radio" name="test" onclick="chickFill4.disabled=false"/>quantity:	<input type="text" id="chickFill4" size="2" value="" disabled="disabled"/>
thank you
Razzy is offline   Reply With Quote
Old 07-06-2012, 12:31 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
<html>
<head>
</head>
<body>
<form>
<input type="radio"  name="test"  onclick="displ(1)"/>in KG:	<input type="text" name = "chickFill1"  id="chickFill1" size="2" value="" disabled="disabled"/>
    <br/>
    <br/>
    <input type="radio" name="test" onclick="displ(2)"/>in lbs:	<input type="text" name = "chickFill2" id="chickFill2" size="2" value="" disabled="disabled"/>
     <br/>
    <br/>
    <input type="radio" name="test" onclick="displ(3)"/>in money:	£<input type="text" name = "chickFill3" id="chickFill3" size="4" value = "00.00" disabled="disabled"/>
     <br/>
    <br/>
    <input type="radio" name="test" onclick="displ(4)"/>quantity:	<input type="text" name = "chickFill4" id="chickFill4" size="2" value="" disabled="disabled"/>
</form>

<script type = "text/javascript">

function displ (which) {
var len = document.forms[0].test.length;  // how many radio buttons in group?
for (var i =1; i<=len; i++) {  // for all the textboxes
document.forms[0]["chickFill" + i].value = "";  // clear the field
document.forms[0]["chickFill" + i].disabled = true; // disable the textbox
}
document.forms[0]["chickFill" + which].disabled = false;  // enable selected textbox
}

</script>

</body>
</html>
test is not a very good name for a group of radio buttons.


Illiterate? Write today for free help. - Government leaflet.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 07-06-2012 at 12:39 PM..
Philip M is offline   Reply With Quote
Old 07-06-2012, 05:04 PM   PM User | #3
Razzy
New Coder

 
Join Date: Jun 2012
Posts: 41
Thanks: 14
Thanked 1 Time in 1 Post
Razzy is an unknown quantity at this point
hey phillips, thank you for the coding, however i tested the codes that you gave, and for some reason the textboxes do not change at all, it stays disabled
Razzy is offline   Reply With Quote
Old 07-06-2012, 06:37 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Razzy View Post
hey phillips, thank you for the coding, however i tested the codes that you gave, and for some reason the textboxes do not change at all, it stays disabled
It works fine for me Check you have copied the code correctly.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Razzy (07-07-2012)
Old 07-07-2012, 05:49 PM   PM User | #5
Razzy
New Coder

 
Join Date: Jun 2012
Posts: 41
Thanks: 14
Thanked 1 Time in 1 Post
Razzy is an unknown quantity at this point
it perfectly works fine now, when i first tested it, i put the javascript coding in between the HEAD section, but this time i literally copied and pasted the whole thing, and it perfectly worked, thank you very much phillips
Razzy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:16 AM.


Advertisement
Log in to turn off these ads.