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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:30:46+00:00 2026-06-01T13:30:46+00:00

So I have a selection list, and if the default value hasn’t been changed

  • 0

So I have a selection list, and if the default value hasn’t been changed from --- then return to the form false. Pretty much for validation purposes so we know they picked a title. The problem is that for some reason prop() is changing the default value to the bottom most value. Is there a way to keep this from happening? Here’s a JSFiddle:

JSFiddle Link

And here’s the code:

HTML

<form onSubmit="return checkSelect()">
<select id="title" name="title"> <option value="---">---</option> <option value="Administrator">Administrator</option> <option value="Asst. Admin.">Asst. Admin.</option> <option value="Director">Director</option> <option value="Asst. Director">Asst. Director</option> <option value="IT Director">IT Director</option> <option value="Manager">Manager</option> <option value="Medical Officer">Medical Officer</option> <option value="Other">Other</option> </select>
    <input type="submit" value="submit" />
</form>

​JS

function checkSelect(){
try{
    var val = $('#title option').attr('selected', 'selected').val();
    alert(val);
    return false;
    }
    catch(err){
        alert(err.message);
    }
}

​EDIT

I tried to change to attr() to see if that would help, but it produces the same problem 🙁

  • 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-01T13:30:47+00:00Added an answer on June 1, 2026 at 1:30 pm

    The attr(attribute, value) function you use is setting the attribute to a value, see the attr doc. Try changing:

    var val = $('#title option').attr('selected', 'selected').val();
    

    to:

    var val = $('#title option:selected').val();
    

    See this jsfiddle.

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

Sidebar

Related Questions

Everyone. I have a little issue with selecting value from the dropdown list. When
I have a list of genders to select. The default selection is 'select' <select
Currently, I have a JList listen to list selection listener. private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt)
I have a list of textboxes created dynamically accroding to the user selection on
I have created an editor template for representing selecting from a dynamic dropdown list
I have the following HTML containing a drop down list (single selection) <script type="text/javascript">
Since I have upgraded from VS2008 to VS2010, I've been having an increasingly infuriating
I am creating a drop down list of all languages. The default language selection
In a Struts 1.x application, I have a form with a simple single-selection html:select
The problem: I have a div where I will have a list of selections

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.