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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:49:59+00:00 2026-05-23T13:49:59+00:00

$(document).ready(function(){ $(‘#userForm’).submit(function(){ user_id = $(‘#user_id’).val(); valid = true; if (user_id > 0) { $(‘#user_id’).removeClass(‘error’);

  • 0
$(document).ready(function(){

$('#userForm').submit(function(){

    user_id = $('#user_id').val();

    valid = true;

    if (user_id > 0) {
        $('#user_id').removeClass('error');
        } else {
        valid = false;
        $('#user_id').addClass('error');
    }



    return valid;

    });

});

The above code should add a class to the user_id select I am using. This code snipet I am using on another page and it works fine but this one just seems to not like me. I have checkec all the variable names and its still not working.

This is validationg a SELECT (drop down menu)

Here it the relative HTML

<form method="post" action="index.php?action=save&course_id=<?php echo $_REQUEST['course_id']?>" id="userForm">
  <input name="company_id" value="<?php echo $companyData->id?>" type="hidden" size="20" />
  <select name="user_id" id="user_id" class="">
    <option value="0" selected="selected">Select a User</option>
    <?php if (count($userListData) > 0) {
            foreach ($userListData as $userList) { ?>
    <option value="<?=$userList->id?>"><?=$userList->firstname?> <?=$userList->surname?></option>
<?php } } ?>
  </select>
  <input name="submit" type="submit" value="Assign this user" />
  </form>
  • 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-05-23T13:50:00+00:00Added an answer on May 23, 2026 at 1:50 pm

    Try:

    if (user_id.length > 0)
    

    This checks if there’s a value for user_id at all, but if the select contains values like “-123” or “0” you might want to try a different approach:

    if(user_id.length > 0) {
       if(parseInt(user_id) > 0) {
           // Has a value and is bigger than zero
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function(){ $(.txtDate).datepicker({ showOn: both, buttonImage: library/ui/datepicker/img/calendar2.gif, dateFormat: yy/mm/dd, buttonImageOnly: true }); //added this checkbox
$('document').ready(function(){ $('[name=mycheckbox]').live('click', function(){ if($(this).is(':checked')) { alert('it is checked'); } else { alert('it is not
$(document).ready( function() { $('input[id^=btnRemoveCategory]').bind( 'click', function(){ if($('input[id^=chkIsBottom_:checked]')) alert('YES YES YES!!!!'); else alert('No NO no!!!!!');
$(document).ready(function() { $(span.link).mouseover(function(e){ $(this.children).css(display,inline); }); }); I'm not a javascript expert, but I've cobbled
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {
Does anybody know why the following code only has effect in FF? $(document).ready(function() {
I have using the following code for developing tabs. $(document).ready(function() { $('#container-1').tabs(); } ....
I want to do this, but haven't figured it quite out yet... $(document).ready(function() {
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have created a function outside of $(document).ready() , but am still using jQuery

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.