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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:00:49+00:00 2026-05-24T16:00:49+00:00

I want to validate this form ignoring default values of input fields. I tried

  • 0

I want to validate this form ignoring default values of input fields. I tried all possible ways with jQuery validate plugin. It’s hard to understand how to use it, since I’m a beginner to JS.

My form looks like that

<?php
require "core/code/includes/db.php";
if (mysqli_connect_errno()) {
        printf("Baza ilə əlaqədə problem var: %s\n Xahiş edirik administrator ilə əlaqə yaradasınız: mail@tural.us", mysqli_connect_error());
        exit();
    }
?>
<form id="reg" method="post" action="core/code/functions/signup.php" onSubmit="return checkForm(this);">
<table width="270px" style="clear:both">
<tr>
<td class="numbers" rowspan="3">
1
</td>
<td colspan="3" style="font-weight:bold; color:#333; font-size:13px">
Əsas məlumatlar 
</td>
</tr>
<tr>
 <td ><input class="part1 default required" type="text" name="fname" value="Adınız"  /></td>
  <td ><input  class="part1 default required"  type="text" name="mname"  value="Atanızın adı"/></td>
 <td ><input  class="part1 default" type="text" name="lname"  value="Soyadınız" /></td>
</tr>
...

...
<input class="button button-gray"  type="submit" value="Tamam" name="submit"/>
</p>
</form>
<script type="text/javascript" src="core/code/js/jquery-ui.js"></script>
<script src="core/code/js/mask.js"></script>
<script src="core/code/js/reg.js"></script>
<script type="text/javascript" src="core/code/js/acompl.js"></script>  

And reg.js

var defaultValues = {
    'fname': 'Adınız',
    'mname': 'Atanızın adı',
    'lname': 'Soyadınız',
    'phone': 'Telefon',
    'email': 'Email',
    'pwd':'Şifrə',
    'region':'Rayon',
    'school':'Məktəb',
    'login':'Istifadəçi adı',
    'class':'Sinif',
    'subject':'Fənnin adını daxil edin',
    'dob': 'Date of Birth'
};
$('input').live('focus', function() {
    var el = $(this);
    if (el.hasClass('default')) {
        el.removeClass('default').val('');
    }
    if (el.attr('id') === 'dob') {
        $(this).mask('99.99.9999', {placeholder:' '});
    }
});

$('input').live('blur', function() {
    var el = $(this);
    var name = el.attr('name');

    // Really we only want to do anything if the field is *empty*
    if (el.val().match(/^[\s\.]*$/)) {

        // To get our default style back, we'll re-add the classname
        el.addClass('default');

        // Unmask the 'dob' field
        if (name == 'dob') {
            el.unmask();
        }

        // And finally repopulate the field with its default value
        el.val(defaultValues[name]);
    }
});
  • 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-24T16:00:50+00:00Added an answer on May 24, 2026 at 4:00 pm

    First I think you should add an id to each form element. I don’t think jQuery will grab a DOM element with its name. Your form has an id but not your input elements.

    So for example, see the input element below (the id can be same as the name):

    <input class="part1 default required" type="text" name="pwd" id="pwd" value="Adınız"  />
    

    Now you can grab that element via jQuery like this: alert($('#pwd').val());

    The # before pwd indicates that the element is being selected by its id.
    You could also select an element by referecing its class like this: alert($('.className').val()); but this will select all matching elements with the same class applied to them. To make a single and specific select; you should use ids.

    So, if I understand your question right; you can validate the value of these elements by checking whether they have the default value or if they are empty first. Then checking other criterias such as password length, etc..

        $('#reg').submit(function (event) 
        {
            if ($('#pwd').val() == defaultValues['pwd'] || $.trim($('#pwd').val()) == '')
            {
                alert('Please enter a password!');
                return false;
            }
            else
            {
                if ($('#pwd').val().length < 8)
                {
                    alert('Password must have 8 characters at least!');
                    return false;
                }
            }
        });
    

    Note: I agree with Jared. You should validate this form on the server-side too; since the code is visible in the browser and can easily be by-passed.

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

Sidebar

Related Questions

Say you have a web form with some fields that you want to validate
Is there is any way to validate form using jquery on dynamic fields. I
This is probably a dumb question - I'm using Jquery to validate the form.
I have designed one sign-up form,in this form after getting all necessary values I
I'm using the jQuery Validator plugin successfully on a form. This form is a
Hi I want to validate a form using a button, but this button call
I am Using jquery validate() plugin . i hava a combobox in form that
I want to validate the input of a form before saving it to database
I want my errors to float above, left-justified, the input field that doesn't validate.
I have a XAML input form which the user fills out. I want to

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.