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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:10:02+00:00 2026-06-16T01:10:02+00:00

In a drop down menu, I have each option displayed like below as an

  • 0

In a drop down menu, I have each option displayed like below as an example:

scomp23 - Jack Turner

Now with this code below:

var text = $(this).find('option:selected').text();
var split = text.split(' - ');
$('#currentAdminAlias').val( split[0] );     
$('#currentAdminForename').val( split[1] );   
$('#currentAdminSurname').val( split[2] );  

What I am trying to do is display scomp23 in #currentAdminAlias text input (this works fine), display Jack in #currentAdminForename text input and display Turner in #currentAdminSurname text input.

The problem I am having is that it displays both forename and surname in the #currentAdminForename text input only.

Now I know why this happens but my question is how can I display the forename and surname in separate text inputs?

  • 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-16T01:10:04+00:00Added an answer on June 16, 2026 at 1:10 am
            var text = $(this).find('option:selected').text();
            var split = text.split(' - ');
            var names = split[1].split(' ');
            $('#currentAdminAlias').val( split[0] );     
            $('#currentAdminForename').val( names[0] );   
            $('#currentAdminSurname').val( names[1] );
    

    Or consider attaching each of the values you want to the option element as an HTML 5 data attribute. Which would give you

            var element = $(this).find('option:selected');
            $('#currentAdminAlias').val(element.data('alias'));
            $('#currentAdminForename').val(element.data('forename'));
            $('#currentAdminSurname').val(element.data('surname'));
    

    With a sample option element looking like

            <option data-alias="scomp23" data-forename="Jack" data-surname="Turner">
              scomp23 - Jack Turner
            </option>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drop down menu with 3 values. each has an option id.
I have an HTML item for a 'drop down menu', structured like this... <li
i have a simple dropdown menu like this below: <select name=category[] id=category class=icon-menu> <option
I have a drop down menu which fills with some doc names. Now when
I have a drop down menu made with Jquery. Right now, if you hover
We have a drop-down menu of volumes in our UI, and I'd like to
I have a page with several multiselect drop-down menus. Each menu has a general
So i have a drop down menu, in each of the menu list there
I have a dynamic drop down menu which displays each value from number 1-
I have a drop down menu below: $form = <form action=' . htmlentities($_SERVER[PHP_SELF]) .

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.