4 Replies - 1529 Views - Last Post: 18 November 2010 - 04:30 AM

#1 36thChamber  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 10

enabling radio buttons

Posted 16 November 2010 - 04:17 AM

hey guys im new here, ive had a little look around the site and google(which mostley braught me to this site) and im having a few problem with some coding for my website. My lecturers (which i pay 3grand a year to attend the university) havent even been able to figure out the problem (what a joke) . . . im pretty sure it because im using notepad and i probably have just missed something so simple!! but anyway :- what im trying to do is using html and javascript is, when a certain radio button on my form is clicked , another set of radio buttons become enabled

//find my current code below//

_____________________________________________________________________________

<html>
<head>
<title> Ticket Order Form </title>
<link type="text/css" rel="stylesheet" href="style.css">

<script Language=Javascript>

function returnJourney(form){
if (ticket_order.journeyType[1].checked=="True"){
ticket_order.RetDate[0].disabled=false;
}
}

</Script>

</head>

<body>


<Form name='ticket_order'>
<center><Table>



<tr><td><h3>Please Choose A Date and Time of Departure<h3><td>
<tr><td><input type="radio" name="DepDate">11th November @ 08:00 <td>
<tr><td><input type="radio" name="DepDate">11th November @ 12:00 <td>
<tr><td><input type="radio" name="DepDate">11th November @ 17:30<td>
<tr><td><input type="radio" name="DepDate">12th November @ 08:00<td>
<tr><td><input type="radio" name="DepDate">12th November @ 12:00 <td>
<tr><td><input type="radio" name="DepDate">12th November @ 17:30 <td>


<tr><td><br></td></tr>
<tr><td><h3>Please Choose Whether Your Journey will be a Single or Return Journey<h3><td>

<tr><td><input type="radio" name="journeyType" onclick='returnJourney(ticket_order)'> Single</td><td><input type="radio" name="journeyType" onclick='returnJourney(ticket_order)'>Return</td>

<tr><td><br></td></tr>


<tr><td><h3>Please Choose A Date and Time of Return<h3><td>
<tr><td><input type="radio" name="RetDate" disabled="true">12th November @ 09:30 <td>
<tr><td><input type="radio" name="RetDate" disabled="true">13th November @ 09:30 <td>
<tr><td><input type="radio" name="RetDate" disabled="true">14th November @ 09:30<td>
<tr><td><input type="radio" name="RetDate" disabled="true">15th November @ 09:30<td>
<tr><td><input type="radio" name="RetDate" disabled="true">16th November @ 09:30 <td>
<tr><td><input type="radio" name="RetDate" disabled="true">17th November @ 09:30 <td>


</Table></center>

</Form>

</body>
</html>

Is This A Good Question/Topic? 0
  • +

Replies To: enabling radio buttons

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: enabling radio buttons

Posted 16 November 2010 - 05:12 AM

ok, just a couple of points. In your function you are passing in the name of the form with the form variable, but instead of using the variable you just use the name of the form directly. Second, if you are wanting to change the value of all of the radiobuttons in the RetDate radiobutton array to enabled you will need to use a for loop to iterate through each element.
Right now you would only enable the first radiobutton. Your function should look something like this

function returnJourney(form){
  // use the passed in form
  if (form.journeyType[1].checked){
    // iterate through each of the radiobuttons
    for (var i=0; i<form.RetDate.length; i++) {
      // Do whatever with each of the buttons
    }
  }
}


Was This Post Helpful? 1
  • +
  • -

#3 36thChamber  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 10

Re: enabling radio buttons

Posted 16 November 2010 - 07:14 AM

Thanks for the reply, i knew the coding i put in would only affect the first radio button (RetDate[0]), because the code to actualy make that one become enabled wasn't working, and i wanted to correct that before making it for all of them. But thankyou for reminding me a loop function can be used as i would have probably just set them all indervidually to enabled.

The code itself to make them enabled however is the code that isnt workiing and is what i need help with!

function returnJourney(form){
//use the passed in form
if (form.journeyType[1].checked){
//iterate through each of the radio buttons
for (var i=0; i<form.RetDate.length; i++) {
//do whatever with each of the buttons

ticket_order.RetDate[i].disabled=false; << is this coding the correct javascript coding to make it enable, or is the problem within the coding where i call the java script on mouse click

<input type="radio" name="journeyType" onclick="returnJourney();"> Single</td><td><input type="radio" name="journeyType" onclick="returnJourney();">Return

Thanks in advance
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: enabling radio buttons

Posted 16 November 2010 - 09:40 PM

Worked when I tested it
form.RetDate[i].disabled = false;


Was This Post Helpful? 0
  • +
  • -

#5 36thChamber  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-November 10

Re: enabling radio buttons

Posted 18 November 2010 - 04:30 AM

ahh thanks buddy , i had

ticket_order.RetDate[i].disabled
and
onclick=returnJourny()

when i should of had

form.RetDate[i].disabled
and
onclick=returnJourny(form)

Thanks for your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1