Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:45+00:00 2026-06-17T20:18:45+00:00

i am trying to understand Backbone.js and how it works. i have created two

  • 0

i am trying to understand Backbone.js and how it works. i have created two textboxes that takes any values, and onclick of button(Multipy) the values are displayed in the boxes below, which works but i want the multiplication of two values to be shown in the third box – i tried to assign the both values to variables and multiply but it doesn’t seems to work. i think there is some problem with the returned value from textboxes, think it is NAN. Anyway please have a look and advise. i have commented out the code that is not working.
live url : http://egoless.co.uk/learning/learn_backbone/first-backbone-app.php

  <!DOCTYPE html>
  <html>
    <head>
    <title>Testing</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="underscore.js">
  </script><script type="text/javascript" src="backbone.js"></script>
  <style>
  .size {
    width: 100px;
    height: 30px;
    border: solid 1px red;
    float: left;
    margin-left: 10px;
    text-align: center;
    font-weight: bold;
  }
  </style>
    </head>
    <body>
    <input type="text" id="box1" />
  &nbsp;
  <input type="text" id="box2" />
  &nbsp;
  <button id="myBtn">Multiply</button>
  <br>
  <br>
  <div id="myBox" class="size"></div>
  <div id="myBox2" class="size"></div>
  <div id="myBox3" class="size"></div>

  <script>

  (function($){
  //defining model 1
    PersonModel1 = Backbone.Model.extend({

      defaults:{
              age : function(){

               return  $("input#box1").val();

              }
          }
    });

    myPerson1 = new PersonModel1();

    //defining model 2
    PersonModel2 = Backbone.Model.extend({

      defaults:{
              age : function(){

               return $("input#box2").val();

              }
      }
    });

    myPerson2 = new PersonModel2();

    //defining collection


    Group = Backbone.Collection.extend({
          Model: PersonModel1,
          Model: PersonModel2,
          url:"#"

      })

          People = new Group([]);
          People.add(myPerson1);
          People.add(myPerson2);  

    //adding view

    ResultView = Backbone.View.extend({
          el:'button',
          events:{
              'click':'render'
          },
        render:function(){

          val1 = myPerson1.get('age');
          val2 = myPerson2.get('age')
          val3 = val1*val2 // not working
          $('div#myBox').html(val1);
          $('div#myBox2').html(val2);
          $('div#myBox3').html(val3); // not working
          $('input#box1').val("");
          $('input#box2').val("");
          return this;
          }
      })




    $(document).ready(function(e) {
       myResultView = new ResultView();
    });

  })(jQuery);

  </script>
  </body>
  </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:18:46+00:00Added an answer on June 17, 2026 at 8:18 pm

    in defaults section of model definition you can only assign value to the attributes.
    to return value age you should write separate function.

              defaults:{},
              age : function(){
               return  $("input#box1").val();
              }
    

    and you can call like this

          val1 = myPerson1.age();
          val2 = myPerson2.age();
          val3 = val1*val2 ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand how backbone.js collections work. Assuming I have a database of,
I'm trying to understand how Backbone.js model validation works, but I'm seeing some odd
I am trying to learn backbone. I understand that el is the element that
Trying to understand the Android framework model. I have an application that needs to
I am trying to understand the MVC backbone.js. I came across a article that
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand something. I created a d:\svn\repository on my server. I committed folders
I am trying understand how multi queries work in mysqli. But I confess that
Trying to understand the filter function of AngularJS most of the examples have the
Trying to understand why i don't have to convert null to DBNull when using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.