Javascript drop down box change

  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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>
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

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
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

I reposted the script, please use that one
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

P.S I don't know why you are using an array for a control that only allows one selected value?
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

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
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

So increment the name in the id field and function call field
  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

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: Bogey and 95 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.