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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:24:28+00:00 2026-05-18T21:24:28+00:00

I have a list of genders to select. The default selection is ‘select’ <select

  • 0

I have a list of genders to select. The default selection is ‘select’

<select id="gender" >
<option value="select" selected>Select:</option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>

in jQuery:

$.post( 'register.php, {
  telp: $("#telp").val(),
  postcode: $("#postcode").val(),
  gender: $("#gender option[value='select']").attr('selected','selected')
}, ...

in PHP

$gender = $_POST['gender'];
if($gender == '') {
   echo 'Please select gender';
}

I want either ‘Male’ or ‘Female’ to be selected not the default value.
if default option value ‘select’ is selected, it will echoing the error .. ‘Please select gender’

  • 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-18T21:24:29+00:00Added an answer on May 18, 2026 at 9:24 pm

    $("#gender option[value='select']").attr('selected','selected') this selects the option element with the value select. And make that the selected option. So whenever this code is executed the default value will be selected automaticly.

    If you want the textnode of the selected element then use $("#gender option:selected").text() or $("#gender option:selected").val() to get the value (0 or 1). In your php code, use this

    $gender = $_POST['gender'];
    if($gender == 'select' || $gender = 'Select:') {
       echo 'Please select gender';
    }
    

    Even better is to check for the right value.

    $gender = $_POST['gender'];
    if($gender != 'Male' && $gender != 'Female') {
       echo 'Please select gender';
    }
    if($gender != 1 && $gender != 0) {
       echo 'Please select gender';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select list of genders. Code: <select> <option>male</option> <option>female</option> <option>others</option> </select> I
I have a gender select field (--Select--, Male, Female) and I'm populating that in
I have a drop down button for selecting the gender (Male or female) and
i have list of rows that user select and i want to delete them,
i have list of images and on mouse over there is option box shows
I have a list of tuples, say (name, number, birthday, gender). If I wanted
I currently have a form in which I can select a list of options
i have a list of collection which returns the following result: GenderID Name Gender
I have list of input area in the form with id like contact1_title, contact2_title,
I have list of articles on the page in table and 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.