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 8981757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:24:56+00:00 2026-06-15T20:24:56+00:00

I have a ASP.Net MVC4 website that uses twitter bootstrap along with Knockoutjs. One

  • 0

I have a ASP.Net MVC4 website that uses twitter bootstrap along with Knockoutjs. One of the requirements is to refresh the view model when the user toggles between some options. To do this, I have setup the following radio buttons

<div id = "myradio" class="btn-group" data-toggle="buttons-radio">
  <button value="1" type="button" class="btn btn-primary active" data-bind="click: refresh">1</button>
  <button value="2" type="button" class="btn btn-primary" data-bind="click: refresh">2</button>
  <button value="3" type="button" class="btn btn-primary" data-bind="click: refresh">3</button>
</div>​

My Knockoutjs view model is

function ViewModel() {
    var self = this;

    //this function is called when the radio button is clicked
    self.refresh = function(){
    alert($('#myradio > button.active').val());
    };
}

The problem I am having is that the click event is firing too soon and giving me the previous value of the radio button instead of current value. To demonstrate this problem, I have setup a jsfiddle

http://jsfiddle.net/73yMR/2/

Is there any way for me to get the current value? Does knockoutjs allow the event to be passed into the “refresh” function? I am open to any idea as long as I can detect which radio option is selected when the refresh function is run.

  • 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-15T20:24:57+00:00Added an answer on June 15, 2026 at 8:24 pm

    Knockout passes the event object as the second argument (the first argument is the “current data”) to the click handler function (you can read more about this in the documentation)

    So the following code will produce the expected result:

    self.refresh = function(data, element){
        alert($(element.currentTarget).val());
    };
    

    A working JSFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC4 web api that uses fluent NHibernate, but when I
I have an ASP.NET MVC4 app which uses DotNetOpenAuth 4.0.1 to authenticate users with
I have planned to go for asp.net MVC4 web API. Any one can compare
I just upgraded my project from ASP.NET MVC1.0 to ASP.NET MVC4.0 One thing that
I have a Asp.Net MVC4 website which can connect to multiple databases depending on
I have an using ASP.NET MVC 4.5 that uses some css files. The css
I have a fileresult method in asp.net mvc4 that returns a report in an
I have an existing Web Site that uses multiple ASP .Net Web Forms projects.
I have an ASP.NET MVC4 website implementing a REST API, which I'm consuming from
I have a web site built using ASP.NET MVC4 that I can publish fine

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.