Monday, 26 January 2015

Can you spot the Child at risk?

Every day in the U.K. on average 2 young people commit Suicide and there are 32 attempts!

Imagine a class of school children, when you look at them they may all be smiling on the outside but what if you could see how they really feel on the inside?




 Get some SALT it could save a life!

Friday, 23 January 2015

Tidy Chop in your kitchen?


Tidy Chop

Makes preparing food tidier and quicker!

Fed up of having to stop in the middle of food preparation to clear your board of waste?
Well now there is Tidy Chop created by myself one Christmas after thinking there must be a quicker and tidier way.

Aimed at the Catering trade and made out of 304 catering grade stainless steel.  Tidy Chop sits on your workbench taking a standard size chopping board (450mm x 300 mm) and 1/3 (325mm x 176mm) Gastronome pan up to 150mm deep.

Whatever your preparing this is sure to become a valuable part of your kitchen equipment and with 2 versions available Tidy Chop can really speed up your preparation time.

Standard Tidy Chop consists of 1 Gastronome pan where as the Premium 3 pans 1 either side of the board and 1 in the middle.

Inquire now

If you can't Speak it, Write it!

Sometimes asking for help during the darkest times is very hard so if you feel you can't speak to someone try writing to them.

When i was feeling very depressed and suicidal i didn't feel i could talk to my doctor so i wrote him a letter and booked an appointment and handed him a letter.

If you can't Speak it, Write it!

Tell your doctor how your feeling, how long it's been going on for and if you know what may have triggered the thoughts.  Feeling Suicidal doesn't make you MAD or mental!  It just means you need a little bit of help and in life we all need help at sometime or other.

Keeping a diary can help, i used to mark my day out of 10 (10 being the best) and and put a little comment about anything that may have triggered my score.

Remember Suicide is a permanent solution to a temporary problem.

Helpful link http://www.metanoia.org/suicide/

Tuesday, 20 January 2015

Dynamic drop-down from XML (2 drop-downs 1 populates other)

Question
How can i use my XML file to populate two drop-downs where the 1st one defines whats displayed in the second.

Answer
 
<script type="text/javascript">
/* wait until DOM has loaded */
$(document).ready(function() {
    /* declare array to store categories in */
    var categories = [];
    /* load a remote page using an HTTP request. */
    $.ajax({
        /* type of request */
        type: "GET",
        /* url where request is sent */
        url: "pop.xml",
        /* type of data we expect back */
        dataType: "xml",
        /* function to be called if the request is a success */
        success: function(xml) {
            /* declare variable for recipe select and hide  */
            var selectCategory = $('#selectCategory');
            var listRecipe = $('#listRecipe');
            $(listRecipe).hide();
            /* parse xml file and find each recipe node */
            $(xml).find('recipe').each(function() {
                /* for each recipe node get the category */
                var category = $(this).find('category').text();
                /* put each category into our array */
                categories.push(category);
            });
            /* use our function to sort categories and remove duplicates */
            getUnique()
                /* when selectCategorys select is changed */
            $("#selectCategory").change(function() {
                /* empty recipe select then show */
                listRecipe.empty();
                $(listRecipe).show();
                /* declare variable for value of category selected */
                var selectCategory = $('#selectCategory').val();
                /* parse xml file and find each recipe node */
                $(xml).find('recipe').each(function() {
                    /* for each recipe node get the category and title */
                    var category = $(this).find('category').text();
                    var title = $(this).find('title').text();
                    /* if selected category matches category in xml file add it to listRecipe select */
                    if (category == selectCategory) {
                        listRecipe.append("<option value='" + category + "'>" + title + "</option>");
                    }
                });
            });
        },
        error: function() {
            $('#recipeFinder').hide();
            alert("Error: Something went wrong");
        }
    });

    function getUnique() {
        /* declare variables and array */
        var options = $('#selectCategory');
        var uniqueCategories = [];
        /* iterate over array categories */
        for (var i = 0; i < categories.length; i++) {
            /* if category in categories array is not in outputArray add it */
            if ((jQuery.inArray(categories[i], uniqueCategories)) == -1) {
                uniqueCategories.push(categories[i]);
            }
        }
        /* iterate over array outputArray and add each item to selectCategory select */
        for (var i = 0; i < uniqueCategories.length; i++) {
            options.append('<option value="' + uniqueCategories[i] + '">' + uniqueCategories[i] + '</option>');
        }
        /* replace 1st item in selectCategory and select it */
        options.children(":first").text("please make a selection").attr("selected", true);
    }
});
</script> 
 
Demo xml-miltiple-select.php

Wednesday, 14 January 2015

Load HTML file from Dynamically created drop-down created from XML file.

Question
How can i now load the HTML file selected from the Dynamically created drop-down.

Answer
<script type="text/javascript">
    /* check browser supports XMLHttpRequest object and create one else create ActiveXObject */
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    /* create an instance of the XMLHttpRequest object, open a URL, and send the request. */
    xhr.open("GET", 'soups/soups.xml', false); // 
    xhr.send();
    /* get the response of the request (sent as string) */
    xhrStr = xhr.responseXML;
    /* get required elements */
    var xhrTitle = xhrStr.getElementsByTagName("title");
    var xhrFilename = xhrStr.getElementsByTagName("filename");
    /* add select tag to variable */
    var str = '<select name="soups" id="soups">';
    str += '<option value="">Select a soup</option>';

    /* loop through all title tags (will get filename tags found between title tags) */
    for (i = 0; i < xhrTitle.length; i++) {
        /* with the values we get add them to option tag each time we run through the loop */
        str += '<option value=' + xhrFilename[i].childNodes[0].nodeValue + '>' + xhrTitle[i].childNodes[0].nodeValue + '</option>';
    }
    /* close select */
    str += '</select>';
    /* put select element inside createSelect */
    document.getElementById("createSelect").innerHTML = str;
    /* when dom ready and select changes run script */
    window.onload = function() {
            if (window.addEventListener) {
                document.getElementById('soups').addEventListener('change', loadRecipe, false);
            } else if (window.attachEvent) {
                document.getElementById('soups').attachEvent("onchange", loadRecipe);
            }
            /* get value of selected soup and insert it into the page using object data */
            function loadRecipe() {
                var x = document.getElementById("soups").value;
                document.getElementById("showRecipe").innerHTML = '<object data="' + x + '" type="text/html" width="500" height="700"></object>';
            }
        }
</script>
Demo xml-select-html.php

Tuesday, 13 January 2015

Populate drop-down list from XML

Question
So now i have what i want how can i put that into a select tag?

Answer
<script type="text/javascript">
    /* check browser supports XMLHttpRequest object and create one else create ActiveXObject */
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    /* create an instance of the XMLHttpRequest object, open a URL, and send the request. */
    xhr.open("GET", 'soups/soups.xml', false); // 
    xhr.send();
    /* get the response of the request (sent as string) */
    xhrStr = xhr.responseXML;
    /* get required elements */
    var xhrTitle = xhrStr.getElementsByTagName("title");
    var xhrFilename = xhrStr.getElementsByTagName("filename");
    /* add select tag to variable */
    var str = '<select name="Soups">';
    /* loop through all title tags (will get filename tags found between title tags) */
    for (i = 0; i < xhrTitle.length; i++) {
        /* with the values we get add them to option tag each time we run through the loop */
        str += '<option value=' + xhrFilename[i].childNodes[0].nodeValue + '>' + xhrTitle[i].childNodes[0].nodeValue + '</option>';
    }
    /* close select */
    str += '</select>';
    /* put select element inside createSelect */
    document.getElementById("createSelect").innerHTML = str;
</script>


Demo xml-select-tag.php

What's all this parent child thing about in XML? (Tree of recipes.xml)

Question
What's all this parent child thing about in XML?

Answer
Here is the recipe.xml Tree structure shown as a flowchart which should help explain the basics.

XML Tree