From c69ab8c2bc8dfa59070249dd434219d83a792dbc Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 20 Oct 2015 23:00:27 +0200 Subject: Drop dependency on jQuery. Hopefully XMLHttpRequest is supported and standardised enough to work accross browsers now. --- public/regform.js | 36 +++++++++++++++++++++++------------- views/layout.erb | 1 - 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/public/regform.js b/public/regform.js index 42bbd58..a74d087 100644 --- a/public/regform.js +++ b/public/regform.js @@ -1,19 +1,29 @@ -$(function() { +function fetch(url, id) { + var req = new XMLHttpRequest(); + req.onload = function() { + var element = document.getElementById(id); + var node = document.createElement("div"); + node.innerHTML = this.response; + element.appendChild(node); + }; + req.open("GET", url); + req.send(); +} + +window.onload = function() { var num_members = 0; var num_songs = 0; - $('#add-member-button').click(function(event) { + var add_member_button = document.getElementById('add-member-button'); + var add_song_button = document.getElementById('add-song-button'); + + add_member_button.onclick = function() { num_members += 1; - $.get('member/new/' + num_members, function(data) { - $('#form-members').append(data); - }); - }); + fetch('member/new/' + num_members, 'form-members'); + }; - $('#add-song-button').click(function(event) { + add_song_button.onclick = function() { num_songs += 1; - $.get('song/new/' + num_songs, function(data) { - $('#form-songs').append(data); - }); - }); - -}); + fetch('song/new/' + num_songs, 'form-songs'); + }; +}; diff --git a/views/layout.erb b/views/layout.erb index eb1d803..a8fc171 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -2,7 +2,6 @@ - Norsk Urskog 2015 - Påmeldingsskjema for band -- cgit v1.2.3