mercredi 22 mars 2017

How do you assign unique id for every checkbox?

i am trying to check whether are the check boxes checked. However, the problem i am facing is that i used a loop(xsl:for-each) to automatically generate the checkboxes depending on the XML. Since i am auto generating them, i cant set different IDs for every checkboxes, which prevents me from updating the specific checkbox's attribute for an indication that it is checked. Plus, whenever i checked a checkbox( be it the first or the last one), the first checkbox will be the one that gets updated. Can someone offer me a suggestion? or at least put me in a right direction? Thanks in advance.

Here is my XSLT code:

  <xsl:if test="$type='MultiList'">
          <xsl:for-each select="./options/item">
            <xsl:element name="input">
              <xsl:attribute name="type">checkbox</xsl:attribute>
              <xsl:attribute name="id">hey</xsl:attribute>
              <xsl:attribute name="onchange">hii()</xsl:attribute>
              <xsl:attribute name="score">
                <xsl:value-of select="@score"/>
              </xsl:attribute>
              <xsl:attribute name="value">
                <xsl:value-of select="item"/>
              </xsl:attribute>

            </xsl:element>
            <label>
              <xsl:value-of select="."/>
            </label>
          </xsl:for-each>
        </xsl:if>

Here is the javascript:

<script>


    function hii(){

    var a = document.getElementById('hey');
    a.setAttribute("score","1");
    }
  </script>




Aucun commentaire:

Enregistrer un commentaire