0

I have some code which I got from jquery which i modified a bit to that all checked box values will populate a text input element.

this works perfectly on jsfiddle.. see link to demo http://jsfiddle.net/aAqt2/

but when I try it on my out site, it does not work.. any Idea why? see my code below

<html><head>
<script src="/js/jquery.min.js"></script> 
<script type="text/javascript">
$('input').on('change', function() {
   var values = $('input:checked').map(function() {
   return this.value;
   }).get();
  $('#output').val(values.toString());
});
</script>
</head>
<body>
<from name="test">
<table>
<tr>
       <td><input type=checkbox value="1"></td>
</tr>
<tr>
      <td><input type=checkbox value="2"></td>
 </tr>
<tr>
       <td><input type=checkbox value="3"></td>
</tr>
<tr>
     <td><input type=checkbox value="4"></td>
</tr>
<tr>
    <td><input type=checkbox value="5"></td>
</tr>
<tr>
    <td><input type="text" id="output"></td>
</tr>
</table>
</form>
</body>
</html>
0

3 Answers 3

3

You need to wrap your code in a document ready call or place it at the end of the page before the closing body tag. JSfiddle is doing that for you automatically.

Ex:

$(document).ready(function () {
    $('input').on('change', function () {
        var values = $('input:checked').map(function () {
            return this.value;
        }).get();
        $('#output').val(values.toString());
    });
});
Sign up to request clarification or add additional context in comments.

Comments

2

Wrap your code in a DOM ready function:

$(document).ready(function() {
    //code here
});

Comments

0

You need to put your code inside a ready function.

$(document).ready(function () {
$('input').on('change', function() {
   var values = $('input:checked').map(function() {
   return this.value;
   }).get();
  $('#output').val(values.toString());
});
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.