Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    gwh
    gwh is offline
    New Coder
    Join Date
    Sep 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populate an input field based on radio button value

    Hi,

    I'm trying to populate the input field with an id of "event-price" with the value of the currently selected radio button. I've tested the code out at the following url but I'm not having any luck:

    Edit fiddle - JSFiddle

    I wondered if someone could tell me what I'm doing wrong?

    Really appreciate any help.

    Code:
    <p><strong>Cost:</strong>
    
    <span id="member-price" class="populated"><input type="radio" name="price" value="25" check="checked" class="eventAmount" /> $25 Member</span>
    
    <span id="student-price" class="populated"><input type="radio" name="price" value="10" class="eventAmount" /> $10 Student</span>
    
    </p>
    <p>
        <input type="text" name="event-price" id="event-price" maxlength="255" />
    </p>
    Code:
    $(function(){
    		// When the Event amount is checked
    	$(".eventAmount").click(function(){
    		$("#event-price").val(this.value); // Put the value into the Amount field
    	});
    });

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,474
    Thanks
    13
    Thanked 361 Times in 357 Posts
    you need to include the jQuery library as well.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •