Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <link href="//cdn.jsdelivr.net/picnicss/4.1.1/picnic.min.css" rel="stylesheet">
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <h1>Hello Mag.JS!</h1>
  <a target="_top" href="https://github.com/magnumjs/mag.js">GitHub</a>
  <hr/>
  <div id="tickets">
    <h2>How many tickets?</h2>
    <table>
      <tbody>
        <tr class="ticketTypeRow">
          <th class="ticketType">
            Senior
          </th>
          <td class="numberofTickets">
            <input name="quantity" type="number" min="0" maxlength="2" size="1">
          </td>
          <td class="timesX">x</td>
          <td>$ <span class="pricePerTicket"></span>
          </td>
          <td class="equals">= $</td>
          <td class="rowTotal">
            <input name="total" type="text" style="border:0px" class="sub" size="8" readonly="readonly" tabindex="-1" value="0.00">
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <script src="//rawgit.com/magnumjs/mag.js/master/mag-latest.min.js"></script>
</body>
</html>
 
.hide {
  display: none;
}
a {
  display: block;
}
a:after {
  content: " \bb";
}
 
/* MagJS - Data List Binding to State */
var tickets = {}
tickets.controller = function(props) {
  // merge the props with the module's state/html
  mag.utils.merge(this, props);
}
tickets.view = function(state, props) {
  state.$quantity = {
    _oninput: function(event, index, node, data) {
      state.ticketTypeRow[data.index].total = state.ticketTypeRow[data.index].quantity * state.ticketTypeRow[data.index].pricePerTicket
    }
  }
}
var props = {
  ticketTypeRow: [{
    quantity: 0,
    ticketType: 'senior',
    total: 0.00,
    pricePerTicket: 5.99
  }, {
    quantity: 0,
    ticketType: 'adult',
    total: 0.00,
    pricePerTicket: 5.99
  }, {
    quantity: 0,
    ticketType: 'child',
    total: 0.00,
    pricePerTicket: 3.99
  }],
}
mag.module("tickets", tickets, props)
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers