-1

I have the below snippet of input tags which are not server controls so unable to use required field validators. So i want to use validators using jquery or java script.Can anyone help me with this.

   <div id="win">
        <table>
           <tr>
             <td>
               <div>
             <label id="lblname" for="Name"(required)>Name</label>
           </div>
              <div  id="dname">
               <input data-bind="value: data.Name" id="inpName" />
              </div>
         </td>
             <td>
               <div>
             <label id="lblend" for="End"(required)>End</label>
           </div>
              <div  id="dend">
               <input data-bind="value: data.end"  />
              </div>
         </td>

       </tr>
     </table>
    </div>


    <script>
    $("#win").validate();
        </script>

tried using this but didnt work.

0

3 Answers 3

0

After trying several option got this working .might help someone.

if ($("#inpName").val() == "" ) {
            alert("Please enter EndBy");
            e.preventDefault();
Sign up to request clarification or add additional context in comments.

Comments

-1

Here is an example for what you are looking

You have to put the things to be validated in a form tag not in a div. Replace the

<div id="win"> with a

<form id="win">

4 Comments

Without using form cant we do it
Yes you cant see the The Question and the answer whichs says It is not possible.
Got it by using the below code but after clicking ok on alert the page is submitting 'if ($("#inpname").val() == "") { alert("Please enter name"); return false;'
Great that my solution worked for you.
-1

You could use HTML5's required attribute, like so:

<input data-bind="value: data.Name" required>

But since it' HTML5 it's not supported by all browsers, you can see the list here. Good luck.

EDIT: Yes, I missed to state that your inputs should be inside a <form> and the validation will be performed on its submit.

2 Comments

Try to wrap your inputs with a form element.
Got it by using the below code but after clicking ok on alert the page is submitting 'if ($("#inpname").val() == "") { alert("Please enter name"); return false;'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.