0

I am working on a conference registration project in html with bootstrap/jquery and have built a unique url for each registrant that captures their session choices using url parameters. If the conference session id was THU_3PM, the url parameter and value would be THU_3PM=1 if they selected it, or THU_3PM=0 if they did not. I've got like 30 sessions, so I have multiple params to look at.

On their simple "check my schedule" page, I've got divs for each session with matching ids, and my thought was to hide all session divs by default and then show the divs that correspond the url params that = 1.

I've gotten jammed up trying to parse the query string and think I might be better off asking for help. Anybody got a simple jquery or javascript example that could help me out? I'd be very appreciative.

user3206
  • 27
  • 4
  • Hows you backend looks like is it `.PHP` or .HTML files where you load these divs from initially ? And how it your url looks like ? – Always Helping Jul 01 '20 at 05:12

2 Answers2

0

Maybe you could try to deal with AJAX ? Something like in jQuery:

$.ajax({
        type: 'POST',
        url: 'youScript.php',
        data: { 'checkSession': 'true' },
        success: function(response) {
            if (response == 'disable') {
                $('div').hide();
                // OR
                $('div').css('display', 'none');
                // OR
                $('div').addClass('hidden');
            }
        }
    });

And something like in PHP:

if (isset($_POST['checkSession'])) {
    if (!isset($_GET['THU_3PM']) && $_GET['THU_3PM'] == 0) {
        echo 'disable';
    }
}

Hope it helps :)

0

Here's what I came up with, based on a related question/answer.

var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = window.location.search.substring(1),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
};
if (getUrlParameter('MON_3PM') === "1") {
    $('#MON_3PM').show();
} else {
    $('#MON_3PM').hide();
};

Still could be more efficient I'm sure, but nice to have something working!

user3206
  • 27
  • 4