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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:43:52+00:00 2026-06-07T22:43:52+00:00

I am trying to write some validation as part of my page that makes

  • 0

I am trying to write some validation as part of my page that makes sure if the textbox has some required text that it will disable the button if its not there.

I have this working perfectly using the following jQuery code:

 <script>
 $(document).on("ready", function () {
     $('input[type="text"]').on('blur', function () {
        var $required = $(this).next().val();
        var $image = $(this).parent().next().children('img');
        var $errors = $('img:visible').length;
        if (($(this).val().indexOf($required) == -1) && ($(this).val() != '')) {
            $image.show();
            $("#submit").prop("disabled", true);
        } else {
            $image.hide();
            //Manually subtract from error otherwise it doesnt subtract until the next focus change
            $errors--;
            if ($errors == 0)
                $("#submit").prop("disabled", false);
        }
    });
});

</script>

The problem occurs when the textbox requires two values. They are stored in a hidden input as a comma seperated string. How do i check that both exist? They can be in there in any order as long as they are both there. I know I can use a .split(‘,’) to get and array and test them but thats the part im stuck on.

I have tried using both .inArray() and .each() but just cannot get anywhere with it.

I tried to set up a fiddle but couldnt get it working.

Here is a cutdown version of the HTML as its an MVC project so most of this is being populated by the models etc.

HTML

  <table width="100%" border="1px solid">
    <tr>
        <th>Source Text</th>
        <th>Translation</th>
    </tr>

    <tr>
        <td>Some text here</td>
        <td><input type="Text"><input type="hidden" value="Some"></td>
        <td><img id="cross" src="../cross.png" class="jq-cross hid" alt="error" /></td>
    </tr>

    <tr>
        <td>Some text here</td>
        <td><input type="Text"><input type="hidden" value="Some,Here"></td>
        <td><img id="cross" src="" class="jq-cross hid" alt="error" /></td>
    </tr>
<tr><td colspan="3"><button id="submit" type="submit">Update Translations</button>  </td></tr>
 </table>

Any help you can give me would be most appreciated. Hopefully I have provided enough information here.

Thanks in advance

  • 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-07T22:43:53+00:00Added an answer on June 7, 2026 at 10:43 pm

    You could write a function to loop over your comma seperated string, something like:

    function isTextInText(text, searchtext) {
        var arr = text.split(',');
    
        for(var i=0, len=arr.length; i < len; i++) {
            if (searchtext.indexOf(arr[i]) == -1) return false;
        }
        return true;
    }
    
    console.log(isTextInText("hello","hello there")); //true   
    console.log(isTextInText("hello,there","hello there")); //true
    console.log(isTextInText("hello,bye","hello there")); //false
    

    Then your if logic could become:

    if (isTextInText($required,$(this).val())
    

    Fiddle – http://jsfiddle.net/e7qkd/

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

Sidebar

Related Questions

I am currently trying to write some code that will accept some FTP details,
I am trying to write some simple code which will read a text file
I am trying to write some code that will generate accurate .proto files from
I'm trying to write a user name validation that has the following restrictions: Must
Im trying to write some unit tests for a couple of merthods that are
I'm trying to write my own Custom Validation attribute but I'm having some problems.
I'm trying to write an interceptor for a web service that will modify the
I am trying to write some validation logic inside of a model for one
I am trying to write some validation code in my class for my GUI.
Basically I am trying to write some code to use for form validation, Im

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.