mercredi 25 janvier 2017

Javascript - onselect checkbox copy value to form field

In a contactform to send an e-mail I can add the subject of the generated mail. I would like the visitor to select with checkboxes the subject. Checkbox has as value "on" or "off". Not really interesting, so when checking te checkbox javascript has to change the value of the hidden 'subject' field to the 'define' subject.
1) My script doesn't work, why?
2) Is it more interesting to use onselect or onchange?
3) If user selects multiple checkboxes, how can I merge the strings?
(note the prepared ' space' before the subjects).

    <script type="text/javascript">
    function define(addsubject){
    document.getElementById ('subject').value = addsubject.value;
    }
    </script>

    My question is about: 
<form>
    <input type="hidden" id="subject">

    <input type="checkbox" onselect="define(' Copywriting')">Copywriting &nbsp;<br>
    <input type="checkbox"  onchange="defineSkubject(' Proofreading & Copy-editing')"> Proofreading & Copy-editing<br>
    ... etc.
</form>




Aucun commentaire:

Enregistrer un commentaire