jeudi 1 décembre 2016

How to change the different values of the field after selecting a different checkbox

Please help with js code. There is a table with checkboxes and text fields:

<form name="rem">
<table class='my-table'>
    <thead>
    <tr>
        <th>The workers</th>
        <th>Urgent</th>
        <th>Usual</th>
    </tr>
    </thead>
    <tbody class='order-set'>
    <tr>
        <td>
            Builder
        </td>
        <td>
            <input type="checkbox" id="h-first" name="first" value="4"/>
            <label for="h-first">One</label>
        </td>
        <td>
            <input type="checkbox" id="h-second" name="second" value="8" />
            <label for="h-second">Two</label>
        </td>
    </tr>
    <tr>
        <td>
            Construction finisher
        </td>
        <td>
            <input type="checkbox" id="f-first" name="first" value="3"/>
            <label for="f-first">One</label>
        </td>
        <td>
            <input type="checkbox" id="f-second" name="second" value="5" />
            <label for="f-second">Two</label>
        </td>
    </tr>
    <tr>
        <td>
            Cleaner
        </td>
        <td>
            <input type="checkbox" id="u-first" name="first" value="2"/>
            <label for="u-first">One</label>
        </td>
        <td>
            <input type="checkbox" id="u-second" name="second" value="4" />
            <label for="u-second">Two</label>
        </td>
    </tr>
    </tbody>
    <tbody class='chioce-result'>
    <tr>
        <td colspan="2">Order Code</td>
        <td>
            <input type="text" name="code" value="------" size="6" READONLY="1" class="result-code" />
        </td>
    </tr>
    <tr>
        <td colspan="2">Order Price</td>
        <td>
            <input type="text" name="price" value="000" size="4" class="result-price"/>
        </td>
    </tr>
    </tbody>
</table>
</form>

I would like that when you select one or more checkboxes to change the value of the category, so that the values of the selected checkboxes summed and changed the first value of the field "Order Price" if selected "urgent" and the second - if the "usual" and in the "Order Code" changed the respective symbols in turn - first checkbox - 1 symbol, the second - the second character and so on, on the values ​​of checkboxes. How to do it, I just can not figure out how to get and change the value of a particular character of the text by clicking INPUT? Who knows please tell me!




Aucun commentaire:

Enregistrer un commentaire