PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] How can I remove a choice from a select list with jQuery?

 October 27, 2022     javascript, jquery, jquery-events     No comments   

Issue

I have the following:

<select name="CityID" id="CityID">
  <option value="99">Select City</option>
  <option value="01H">AAA</option>
   <option value="01I">BBB</option>
</select>

As soon as the clicks on the select to choose an option I would like to remove the first line with option value="99".

Can I do this with jQuery? I think I can do it with the .changed() event but are there other events that will pick up the user clicking on the select before the .changed()?


Solution

$('select[name="CityID"]').focus(function() {
    $('option[value="99"]:first', this).remove();
});


Answered By - Bryan
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing