Home › Forums › JavaScript › Availability Calendar
- This topic is empty.
-
AuthorPosts
-
March 20, 2019 at 3:24 pm #285152
webryan
ParticipantThe 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/JzZYNeMarch 20, 2019 at 4:38 pm #285156Shikkediel
ParticipantFar as I can tell, this should do the trick:
March 20, 2019 at 4:50 pm #285158webryan
ParticipantThank 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?
March 20, 2019 at 5:05 pm #285163Shikkediel
ParticipantThe 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.March 20, 2019 at 5:28 pm #285164webryan
ParticipantI 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!
March 20, 2019 at 5:55 pm #285166Shikkediel
ParticipantCheers, 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).
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.