Be a Supporter!

Dynamic Radio Button

  • 420 Views
  • 5 Replies
New Topic Respond to this Topic
newgiez
newgiez
  • Member since: Apr. 18, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Dynamic Radio Button 2009-04-05 14:16:38 Reply

I'm trying to create a dynamic radio button in my order form for a website I'm working on.

The form defaults on certain items (Item #2) When the page is loaded
ex.
Item #1 (-$50)
Item #2 ($154) [SELECTED]
Item #3 (+$10)
Item #4 (-$20)
Total Amount: $154

What I want my form to do is when the user selects another item I want the total amount to go up or down in the amount according to which item the user choose. I have no idea where to start on this, Could I please get some help.

Also... If its possible....
I would like my form to make some items on the list un-choosable when another item is chosen.
Ex.
Item #1 ($104) [SELECTED]
Item #2 (+$154)
Item #3 (+$10)
Item #4 (-$20) [Cannot be Selected (Disabled Radio Button only when item #1 or item #2 is selected)]

Please help! HTML, PHP, Javascript, ext is acceptable.


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@!@

BBS Signature
polym
polym
  • Member since: Oct. 2, 2007
  • Offline.
Forum Stats
Member
Level 14
Audiophile
Response to Dynamic Radio Button 2009-04-05 14:30:48 Reply

use the onFocus event.

polym
polym
  • Member since: Oct. 2, 2007
  • Offline.
Forum Stats
Member
Level 14
Audiophile
Response to Dynamic Radio Button 2009-04-05 14:43:13 Reply

Working example:

<script type='text/javascript'>
function disable()
{
	document.getElementsByName('group1')[3].disabled = true;
}

function enable()
{
	document.getElementsByName('group1')[3].disabled = false;
}

function twrite(str)
{
	document.getElementById('t').innerHTML += str + "<br />";
}
</script>
<input type="radio" name="group1" value="Milk" onFocus='disable();' onClick='twrite(this.value);' /> Milk<br />
<input type="radio" name="group1" value="Butter" checked onFocus='disable();' onClick='twrite(this.value);' /> Butter<br />
<input type="radio" name="group1" value="Cheese" onFocus='enable();' onClick='twrite(this.value);' /> Cheese<br />
<input type="radio" name="group1" value="Sauce" onClick='twrite(this.value);' disabled /> Sauce<br />
Your orders sir!<br />
<div id='t'>
</div>

not the best but it demonstrates what you want.

newgiez
newgiez
  • Member since: Apr. 18, 2007
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Dynamic Radio Button 2009-04-05 14:52:18 Reply

At 4/5/09 02:43 PM, polym wrote: Working example:

not the best but it demonstrates what you want.

Thank you so much! But, now for the first part.


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@!@

BBS Signature
polym
polym
  • Member since: Oct. 2, 2007
  • Offline.
Forum Stats
Member
Level 14
Audiophile
Response to Dynamic Radio Button 2009-04-05 18:59:20 Reply

At 4/5/09 02:52 PM, newgiez wrote: Thank you so much! But, now for the first part.

Dude I figured it would be common sense, but you have a variable that contains the total amount

then whenever a radio button is selected replace (instead of adding to) the div's innerHTML with the total.

Relish
Relish
  • Member since: Jan. 22, 2008
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Dynamic Radio Button 2009-04-05 20:43:23 Reply

Messing around a little I came up with something like this, that can be easily expanded upon.

http://emminar.com/public/NG/order/