Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Availability Calendar

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #285152
    webryan
    Participant

    The idea is that the resort has cabins numbered 1-4 and each cabin can be reserved from Saturday afternoon one week and checkout Saturday morning the following week. I want the default setting to be unavailable with the table row background being a light shade of red. I’m trying to figure out how to set up the code to have a clicked/active “Cabin 1” button show all of the table rows in which Cabin 1 was available. Then the same with the other Cabins.

    So I figured that I’d have a css class “unavailable” [bg-color: red] as the first class then add “c1 c2 c3, etc” as placeholders to add an “available” class [bg-color: green] with javascript. If a table row has the class “c1” then I want the Cabin 1 button click, to add the class “available” and then a click anywhere else will first remove all “available” classes.

    I’m pretty sure this can be done with javascript and I think this resource https://hype.codes/how-change-elements-class-javascript can help anyone who knows javascript. Reading javascript makes sense to me, but rearranging it to do custom tasks has never worked for me. Any help would be great.

    Code here –
    https://codepen.io/ryan-agrimson/pen/JzZYNe

    #285156
    Shikkediel
    Participant

    Far as I can tell, this should do the trick:

    codepen.io/anon/pen/JzmZyo

    #285158
    webryan
    Participant

    Thank you! For some reason Codepen is freaking out on Safari 12.0.3, but looks great on firefox and chrome. Is this not-compatible for safari?

    #285163
    Shikkediel
    Participant

    The JS is quite basic so I wouldn’t know what would trigger it. Only thing I can think of is that Safari doesn’t like the button being an a link (it would be preferable to use a more semantically correct tag)…

    Does the tweak of adding e.preventDefault() as I have now done in the example fix anything?

    I can’t actually check that browser myself.

    Edit – you can also try adding an empty href="" , omitting it altogether isn’t valid markup I think.

    #285164
    webryan
    Participant

    I tested it it within the website and it works great on safari if I use it as an inline script. Thank you this works fantastic when adding the other cabin classes!

    #285166
    Shikkediel
    Participant

    Cheers, I did indeed make sure that it loops through all the buttons (regardless the amount) and finds the matching classes – in the order in which they appear on the page markup (I reckon that was only the requirement here).

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.