Top Poster
#1 ramon fincken 400
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[solution] Prototype Javascript: Select Multiple Dropdown Items (values)



Rating : 2.1 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> HTML and other markup&programming languages
Beta
Want to be notified by email when this topic gets a reply?  
View previous topic :: View next topic  
Author Message
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 400
Location: A'dam/Diemen, The Netherlands

PostPosted: Wed Aug 26, 2009 8:15 pm    Post subject: [solution] Prototype Javascript: Select Multiple Dropdown Items (values) Reply with quote

So I needed to have all values from:
Code:
  select multiple="multiple" name="cats" id="cats" size="5">
option value="73">Catg Naam</option>
option value="70">CatNaam1</option>
option value="90">CatNaam2</option>
option value="80" >CatNaam3</option>
  </select>


how to do this? ( in order to make it usable for AJAX requests ).
A solution is to serialize them to XML but I needed a string.


Recoded from:
http://ehsan.bdwebwork.com/2006/12/20/j...own-items/

Here's how to get 73+70+80 if 3 options are selected:
Code:

alert(getmultiplevalues($('cats')));


/**
 * Recoded by Ramon Fincken (www.ramonfincken.com) from: http://ehsan.bdwebwork.com/2006/12/20/javascript-select-multiple-dropdown-items/
 */
function getmultiplevalues(input)
  {
    var opt = input;

    var numofoptions = opt.length;
    var selValue = new Array;

    var j = 0;
    for (i=0; i<numofoptions; i++)
    {
      if (opt[i].selected === true)
      {
        selValue[j] = opt[i].value;
        j++
      }
    }

    selValue = selValue.join("+")

    return selValue;
  }
Back to top
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: Wed Aug 26, 2009 8:15 pm    Post subject: [solution] Prototype Javascript: Select Multiple Dropdown Items (values)

Advertisement
Back to top
GravityForms
Advertisement





PostPosted: Wed Aug 26, 2009 8:15 pm    Post subject: [solution] Prototype Javascript: Select Multiple Dropdown Items (values)

Advertisement
Gravity Forms Plugin for WordPress
Back to top
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> HTML and other markup&programming languages All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads