Javascript drop down box change

  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: Jul 18, 2008
  • Posts: 239
  • Loc: Western Australia
  • Status: Offline

Post July 10th, 2009, 7:19 am

I've got two drop down box arrays where users can choose the start and finish time of an event

When the first drop down box (start time) is changed, i'd like the second one (finish time) to change to an hour ahead.

Start:
Code: [ Select ]
<select name="timestart[]" onchange="timefix(this.id)">
<option value="8">8:00</option>
<option value="9">9:00</option>
etc..
  1. <select name="timestart[]" onchange="timefix(this.id)">
  2. <option value="8">8:00</option>
  3. <option value="9">9:00</option>
  4. etc..


Finish:
Code: [ Select ]
<select name="timeend[]">
<option value="9">9:00</option>
<option value="10">10:00</option>
etc..
  1. <select name="timeend[]">
  2. <option value="9">9:00</option>
  3. <option value="10">10:00</option>
  4. etc..


Javascript:
Code: [ Select ]
function timefix(x)
{
var y=document.getElementById(x).value;
document.getElementById(??).value=y+1();
}
  1. function timefix(x)
  2. {
  3. var y=document.getElementById(x).value;
  4. document.getElementById(??).value=y+1();
  5. }


What should I put for the question marks? (above in js)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 10th, 2009, 7:19 am

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 10th, 2009, 7:26 am

Code: [ Select ]
 
<html>
<head>
<script>
function timefix(start, end)
{
var y=document.getElementById(start).value;
document.getElementById(end).value=parseInt(y)+1;
}
</script>
</head>
<body>
<select name="timestart[]" id="timestart[]" onchange="timefix('timestart[]','timeend[]' )">
<option value="8">8:00</option>
<option value="9">9:00</option>
</select>
<select name="timeend[]" id="timeend[]">
<option value="9">9:00</option>
<option value="10">10:00</option>
</select>
</body>
</html>
  1.  
  2. <html>
  3. <head>
  4. <script>
  5. function timefix(start, end)
  6. {
  7. var y=document.getElementById(start).value;
  8. document.getElementById(end).value=parseInt(y)+1;
  9. }
  10. </script>
  11. </head>
  12. <body>
  13. <select name="timestart[]" id="timestart[]" onchange="timefix('timestart[]','timeend[]' )">
  14. <option value="8">8:00</option>
  15. <option value="9">9:00</option>
  16. </select>
  17. <select name="timeend[]" id="timeend[]">
  18. <option value="9">9:00</option>
  19. <option value="10">10:00</option>
  20. </select>
  21. </body>
  22. </html>
Watch me grow
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: Jul 18, 2008
  • Posts: 239
  • Loc: Western Australia
  • Status: Offline

Post July 10th, 2009, 7:46 am

I'm having a bit of trouble putting the first bit into my javascript (it's a dynamic array)

Code: [ Select ]
var start = '<select name="timestart[]" onchange="timefix('timestart[]','timeend[]' )"><option value="8">8:00</option> ... <option value="17">17:00</option></select>';
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 10th, 2009, 7:55 am

I reposted the script, please use that one
Watch me grow
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 10th, 2009, 7:57 am

P.S I don't know why you are using an array for a control that only allows one selected value?
Watch me grow
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: Jul 18, 2008
  • Posts: 239
  • Loc: Western Australia
  • Status: Offline

Post July 10th, 2009, 7:58 am

I'm generating my tables using javascript - a dynamic table.

See here: http://uwadb.com/timetable/setup.php?id=cal
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 10th, 2009, 8:24 am

So increment the name in the id field and function call field
Watch me grow
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: Jul 18, 2008
  • Posts: 239
  • Loc: Western Australia
  • Status: Offline

Post July 10th, 2009, 8:30 am

I'm not sure how to do that.

The apostrophes in the javascript I've got for the table are making it tricky.

Code: [ Select ]
var start = '<select name="timestart[]" onchange="timefix('timestart[]','timeend[]' )"><option value="8">8:00</option> ... <option value="17">17:00</option></select>';


Is there a way to cancel the apostrophe out? Because the php is generating the javascript, a slash in front cancels it in php, and no javascript.

Do you get what I mean?

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 131 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.