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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:52:46+00:00 2026-05-11T02:52:46+00:00

Thanks for reading this. I would have thought it would be as simple as

  • 0

Thanks for reading this.

I would have thought it would be as simple as using the .split function on the select .val(), but I get a js error. This is the code I am using. I will use .each() to loop through the selected items…but would like to understand what I am doing wrong…

If I set opts with a literal..the split works (commented code)

Thanks

<html><head> <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script> <script type='text/JavaScript'> $(function(){     $('#multOpts').bind('click', function() {     //  var opts = 'OPT1,OPT2,OPT3' ;         var opts = $('#select1').val() ;         $('#text1').val(opts);     });     $('#oneOpt').bind('click', function() {         //  var opts = 'OPT1,OPT2,OPT3' ;         var opts = $('#select1').val() ;         var optsArray = opts.split(',') ;         $('#text2').val('1st opt: ' + optsArray[0]);     }); }); // End eventlistener </script> </head><body> <select id='select1' multiple size='5'> <option value='OPT1'>Option 1</option> <option value='OPT2'>Option 2</option> <option value='OPT3'>Option 3</option> <option value='OPT4'>Option 4</option> <option value='OPT5'>Option 5</option> </select> <div> <input id='multOpts' type='button' value='Show Options'/> <input id='text1' type='text'/> </div> <input id='oneOpt' type='button' value='One Option'/> <input id='text2'  type='text'/> </body></html> 
  • 1 1 Answer
  • 2 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. 2026-05-11T02:52:46+00:00Added an answer on May 11, 2026 at 2:52 am

    The val() function when there are more than one option selected returns you already an array, you don’t need to do the split.

        $('#oneOpt').bind('click', function() {             var opts = $('#select1').val();             $('#text2').val('1st opt: ' + opts[0]);     }); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for reading this. I have no idea why this is throwing a NullReferenceException
This is probably something extremely simple but I can't get my head around it
Firs of all thanks for reading this. I'm having trouble updating the progress from
Thanks in Advance for reading and answer this question. I got button in asp
Thanks for reading. I have done a search, read multiple posts (lost count) and
Thanks to reading about error handling on StackOverflow , I discovered Mz-Tools. However, I
I have been reading a lot about this - I feel like I'm very
I have been reading some of the books by Hoglund and I thought I
I have a best practices question. I realize this is subjective but wanted to
I have looked around SO for similar questions, but it seems that this has

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.