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

  • Home
  • SEARCH
  • 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 7709609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:54:18+00:00 2026-06-01T00:54:18+00:00

so im using a simple submit binding to pass a function data: <form data-bind=submit:

  • 0

so im using a simple submit binding to pass a function data:

<form data-bind="submit: printTest">
    Enter a weight in the box: <BR>
    <INPUT TYPE="text" id="inputWeight" VALUE=""><P>
    <button type="submit">Submit</button>
</form>

i just started working with KO so i was to write a basic print function to test this input out:

self.printTest = function(xxx){

        var myTextField = xxx;
    if(myTextField.value != "")
        alert("You entered: " + myTextField.value)
    else
        alert("Would you please enter some text?")
    }

my problem is when i hit submit i get a “you entered: undefined” but when i refresh the page the input that is in the form gets an alert. this is very frustrating! idk if this is a knockout problem or a simple HTML one.

  • 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-01T00:54:19+00:00Added an answer on June 1, 2026 at 12:54 am

    You haven’t showed all the code so I’ll attempt to answer this based on what’s above. First the submit binding simply executes a function when the form is submitted and allows you to stop/confirm the form should submit.

    When submit fires it is passed the form dom element, it is not passed the input value so this code could never work.

    To print the value of the input you first need to bind the value of the input to a value on your model.

    <input type="text" id="inputWeight" value="" data-bind="value: inputWeight" />
    

    You can then alert the value like so.

    var viewModel = function () {
        var self = this;
        self.inputWeight = ko.observable();
    
        self.printTest = function() {
    
            var valueEntered = self.inputWeight();
            if(valueEntered) {
                alert("You entered: " + valueEntered);
            }
            else {
                alert("Would you please enter some text?");
            }
        }
    };
    

    Heres the working fiddle

    FYI – Your initial code/markup had some errors, missing semi-colons incorrect markup which I fixed.

    Hope this helps.

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

Sidebar

Related Questions

I am using XMLHttpRequest to create a simple form submit and pass 2 parameters.
I could submit a form and validate it using a simple anonymous function in
I have a simple form using a POST method, consisting of a text box
I'm using a simple form to upload 5 files: <form enctype=multipart/form-data action=openaccount.php method=post> <h4>Proof
I am working on using prototype to submit a simple login form: http://huddlee.homeip.net/danny/ For
I have form where before i was using simple post with <button name=submit id=register
Using simple type like class A { public int X, Y; } with object
In the Web Flow below I bind form data to a flow variable (lifeCycleForm)
I have a PHP form that needs some very simple validation on submit. I'd
I'm using a simple jquery code that grabs html code form a tag and

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.