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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:39:36+00:00 2026-06-07T01:39:36+00:00

I’m somewhat baffled by knockoutjs. I’ve gone through most of the tutorials and have

  • 0

I’m somewhat baffled by knockoutjs. I’ve gone through most of the tutorials and have a general understanding of how to use it. I can manipulate the UI just fine, but what I can’t understand is how KO communicates with other javascript functions outside of KO.

I think my goal is rather simple and straightforward. I need the value of the radio button that a user selected from a family of radio buttons. Here’s what I have.

HTML

<input type="radio" name="templateStyle" value="DR.php" data-bind="checked: tempStyle">
<input type="radio" name="templateStyle" value="DRH.php" data-bind="checked: tempStyle">
<input type="radio" name="templateStyle" value="PS.php" data-bind="checked: tempStyle">

<p>The template style selected is <span data-bind="text: selectedStyle"></span></p>

<button id="submitTemplate">Submit Template</button>

JS

var radioValue = { rv: "" };

function viewModel() {
    var self = this;

    self.tempStyle = ko.observable("DR.php");
    self.selectedStyle = ko.computed(function() {
            return self.tempStyle();
    },
        self
    );

    return self.selectedStyle();
}
ko.applyBindings(new viewModel());

$("#submitTemplate").click(function() {
    radioValue.rv = viewModel();

    console.log(radioValue.rv); 
});

This works fine on the UI side, but the radioValue.rv object just remains at “DR.php.” How do I update this to reflect the data-bind="text: selectedStyle" value?

I’ve tried variations of radioValue.rv = ko.toJS(viewModel()) but this did not work.

If this is completely wrong, how do I get the value of the templateStyle radio buttons? So I can use it in other aspects of my javascript?

  • 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-07T01:39:38+00:00Added an answer on June 7, 2026 at 1:39 am

    I’m leaving my original question unedited because it shows my mistakes.

    I can’t believe it took me 2 days and a SO question to figure this out, but here it is.

    HTML

    <input type="radio" name="templateStyle" value="DR.php" data-bind="checked: tempStyle">
    <input type="radio" name="templateStyle" value="DRH.php" data-bind="checked: tempStyle">
    <input type="radio" name="templateStyle" value="PS.php" data-bind="checked: tempStyle">
    
    <p>The template style selected is <span data-bind="text: selectedStyle"></span></p>
    
    <button id="submitTemplate" data-bind="click: submitTemplate">Submit Template</button>
    

    JS

    var radioValue = { rv: "" };
    
    function viewModel() {
        var self = this;
    
        self.tempStyle = ko.observable("DR.php"); // Set default selected radio button
    
        self.selectedStyle = ko.computed(function() {
                return self.tempStyle(); // Update viewModel to reflect user input
            },
            self
        );
    
        self.submitTemplate = function() {
            radioValue.rv = self.tempStyle(); // Return user input on button click
    
            console.log(radioValue.rv); // JS object can now be used anywhere
        };
    
    }
    ko.applyBindings(new viewModel());
    

    Basically, I was trying to work outside of the viewModel to early.

    I now see the light and understand why knockout is so good.

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

Sidebar

Related Questions

I am somewhat new to android development and development in general. I have a
Most somewhat modern programming languages have a standard library? It is my impression is
This is somewhat complex (well to me at least). Here is what I have
I have a somewhat strange issue with visual studio. Almost every time I create
somewhat simple problem(to explain) this time: i have an array of markers that i
I am somewhat new to JavaScript, and have been having an issue with a
I'm somewhat baffled by the following behaviour of SBCL garbage collector in REPL. Define
Somewhat confused by GA, I got to thinking .. surely I can track specific
Somewhat often I have to build tables and assign to the table headers names
I somewhat new to Javascript and I'm stuck on this one item. Can someone

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.