mardi 2 juin 2015

Check specific checkbox depending on XML data

I need to find a way to make link XML data and checkbox status. Right now, my code works for textfields, but it needs to activate specific checkboxes depending on what is entered in the XML file.

For example, here's a part of my XML document :

  <Signature name="John Doe">
    <Nom>John Doe</Nom>
    <PG-Ligne1>Graphic designer</PG-Ligne1>
    <PG-Ligne2>Technician Product Specification</PG-Ligne2>
    <PG-Ligne3></PG-Ligne3>
    <PG-Ligne4></PG-Ligne4>
    <PD-Ligne1>450.123.1233 #2357</PD-Ligne1><!--Tel--><icon1>tel</icon1>
    <PD-Ligne2>450.123.1233</PD-Ligne2><!--fax--><icon2>fax</icon1>
    <PD-Ligne3>john@doe.com</PD-Ligne3>
    <PD-Ligne4>http://ift.tt/1dcuvNV;
    <PD-Ligne5></PD-Ligne5>
    <PD-Ligne6></PD-Ligne6>
  </Signature>

I'm working with HTML5 canvas in my page document. When a specific checkbox is checked, it draws an icon. So I would like to be able to type for example :

<!--Tel--><icon1>tel</icon1>

In the "Signature" section, like it is in my example above, and the script would understand the checkbox that needs to be checked is the one with the "iconTel1" ID.

And my jQuery code :

<script type="text/javascript">  
$(function() {
    $.ajax({
        type: "GET",
        url: "signatures.xml",
        dataType: "xml",
        success: parseXml
    });

function parseXml(xml) {
    var $select = $('#Bname');

    $('<option />', { text: 'Please make a selection' }).appendTo($select);

    $(xml).find('Signature').each(function(){
        var title = $(this).attr('name');
        $('<option />', { text: title, value: title }).appendTo($select);
    });

    $select.on("change", function() {
        var filter = $(this).val();
        var $node = $(xml).find("Signature[name='" + filter + "']");

        $("#nom").val($node.find("Nom").text());
        $("#titre-1").val($node.find("PG-Ligne1").text());
        $("#titre-2").val($node.find("PG-Ligne2").text());
        $("#titre-3").val($node.find("PG-Ligne3").text());
        $("#titre-4").val($node.find("PG-Ligne4").text());
        $("#ligne1").val($node.find("PD-Ligne1").text());
        $("#ligne2").val($node.find("PD-Ligne2").text());
        $("#ligne3").val($node.find("PD-Ligne3").text());
        $("#ligne4").val($node.find("PD-Ligne4").text());
        $("#ligne5").val($node.find("PD-Ligne5").text());
        $("#ligne6").val($node.find("PD-Ligne6").text());
        $("#ligne7").val($node.find("PD-Ligne7").text());
    });
}

});

</script>

Kind of hard to explain. In short, I need to be able to check a specific checkbox in my document using its ID by typing a specific word in my XML file.

Thanks a ton!




Aucun commentaire:

Enregistrer un commentaire