cleanup a select/options list - remove same items.

Discussion in 'Javascript' started by Beholder, Jan 21, 2007.

  1. Beholder

    Beholder Guest

    I hope that someone can help me with the following:

    Short background explenation:
    I have a shrfepoint page (newform.aspx) in a item list. On this page is
    a lookup column that displays a lookup of all category items in
    previous items. In the code this results in a select/options list like
    this:

    <SELECT TABINDEX=1
    NAME="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup"><OPTION
    Value="">(None)</OPTION><OPTION VALUE="8">name 1</OPTION><OPTION
    VALUE="10">name 2</OPTION>><OPTION VALUE="11">name 1</OPTION></SELECT>

    Is there a way to clean-up or rewrite this select list before it is
    published and remove the double entry using javascript?
     
    Beholder, Jan 21, 2007
    #1
    1. Advertising

  2. Beholder wrote:

    > Short background explenation:
    > I have a shrfepoint page (newform.aspx) in a item list. On this page is
    > a lookup column that displays a lookup of all category items in
    > previous items. In the code this results in a select/options list like
    > this:
    >
    > <SELECT TABINDEX=1
    > NAME="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup"><OPTION
    > Value="">(None)</OPTION><OPTION VALUE="8">name 1</OPTION><OPTION
    > VALUE="10">name 2</OPTION>><OPTION VALUE="11">name 1</OPTION></SELECT>
    >
    > Is there a way to clean-up or rewrite this select list before it is
    > published and remove the double entry using javascript?


    To clean up:

    -----------------------------------------

    <form>
    <select tabindex="1"
    name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    <option value="">(None)</option>
    <option value="8">name 1</option>
    <option value="10">name 2</option>
    <option value="11">name 1</option>
    </select>
    </form>
    <script type="text/javascript">
    var S =
    document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    while (S.options.length) S.options[0] = null;
    </script>

    -----------------------------------------

    To rewrite the options "without double entries":

    -----------------------------------------

    <form>
    <select tabindex="1"
    name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    <option value="">(None)</option>
    <option value="8">name 1</option>
    <option value="10">name 2</option>
    <option value="11">name 1</option>
    </select>
    <input type=submit>
    </form>
    <script type="text/javascript">
    var N = new Object();
    var S =
    document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    while (S.options.length) {
    if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    S.options[0] = null;
    }
    for (i in N) S.options[S.length] = new Option(i,N);
    </script>

    -----------------------------------------

    I define "removing double entries" as "removing options with the same
    text" which is probably what you meant. The usual naming is <option
    value="[VALUE]">[TEXT]</option>. The criterium that is used to remove
    is not case sensitive.

    When deleting a double entry, the one that comes first is kept with its
    (albeit unique) value. If you want the last one to be kept, change
    if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    into
    N[S.options[0].text] = S.options[0].value;

    Do you really need a name as
    "urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup" for the select ? I
    would counsel to change it into something shorter and more
    alphanumericaloid.

    There is a syntax error in your code at the double >> (at </OPTION>>).

    Hope this helps,

    --
    Bart
     
    Bart Van der Donck, Jan 22, 2007
    #2
    1. Advertising

  3. Beholder

    Beholder Guest

    Thank you Bart,

    I will try your suggestions asap. Thanks for your clear comments and
    suggestions.

    As for the select name, this is the default naming which is used by
    sharepoint. It has given me a hard time too when taking this nam up in
    ie javascript code. It cannot be changed.

    Bart Van der Donck schreef:
    > Beholder wrote:
    >
    > > Short background explenation:
    > > I have a shrfepoint page (newform.aspx) in a item list. On this page is
    > > a lookup column that displays a lookup of all category items in
    > > previous items. In the code this results in a select/options list like
    > > this:
    > >
    > > <SELECT TABINDEX=1
    > > NAME="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup"><OPTION
    > > Value="">(None)</OPTION><OPTION VALUE="8">name 1</OPTION><OPTION
    > > VALUE="10">name 2</OPTION>><OPTION VALUE="11">name 1</OPTION></SELECT>
    > >
    > > Is there a way to clean-up or rewrite this select list before it is
    > > published and remove the double entry using javascript?

    >
    > To clean up:
    >
    > -----------------------------------------
    >
    > <form>
    > <select tabindex="1"
    > name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    > <option value="">(None)</option>
    > <option value="8">name 1</option>
    > <option value="10">name 2</option>
    > <option value="11">name 1</option>
    > </select>
    > </form>
    > <script type="text/javascript">
    > var S =
    > document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    > while (S.options.length) S.options[0] = null;
    > </script>
    >
    > -----------------------------------------
    >
    > To rewrite the options "without double entries":
    >
    > -----------------------------------------
    >
    > <form>
    > <select tabindex="1"
    > name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    > <option value="">(None)</option>
    > <option value="8">name 1</option>
    > <option value="10">name 2</option>
    > <option value="11">name 1</option>
    > </select>
    > <input type=submit>
    > </form>
    > <script type="text/javascript">
    > var N = new Object();
    > var S =
    > document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    > while (S.options.length) {
    > if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    > S.options[0] = null;
    > }
    > for (i in N) S.options[S.length] = new Option(i,N);
    > </script>
    >
    > -----------------------------------------
    >
    > I define "removing double entries" as "removing options with the same
    > text" which is probably what you meant. The usual naming is <option
    > value="[VALUE]">[TEXT]</option>. The criterium that is used to remove
    > is not case sensitive.
    >
    > When deleting a double entry, the one that comes first is kept with its
    > (albeit unique) value. If you want the last one to be kept, change
    > if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    > into
    > N[S.options[0].text] = S.options[0].value;
    >
    > Do you really need a name as
    > "urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup" for the select ? I
    > would counsel to change it into something shorter and more
    > alphanumericaloid.
    >
    > There is a syntax error in your code at the double >> (at </OPTION>>).
    >
    > Hope this helps,
    >
    > --
    > Bart
     
    Beholder, Jan 22, 2007
    #3
  4. Beholder

    Beholder Guest

    After days of searching and reading about javascript, you just made my
    day <big smile>

    It works.

    Thansk you so much...

    Peter


    Beholder schreef:
    > Thank you Bart,
    >
    > I will try your suggestions asap. Thanks for your clear comments and
    > suggestions.
    >
    > As for the select name, this is the default naming which is used by
    > sharepoint. It has given me a hard time too when taking this nam up in
    > ie javascript code. It cannot be changed.
    >
    > Bart Van der Donck schreef:
    > > Beholder wrote:
    > >
    > > > Short background explenation:
    > > > I have a shrfepoint page (newform.aspx) in a item list. On this page is
    > > > a lookup column that displays a lookup of all category items in
    > > > previous items. In the code this results in a select/options list like
    > > > this:
    > > >
    > > > <SELECT TABINDEX=1
    > > > NAME="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup"><OPTION
    > > > Value="">(None)</OPTION><OPTION VALUE="8">name 1</OPTION><OPTION
    > > > VALUE="10">name 2</OPTION>><OPTION VALUE="11">name 1</OPTION></SELECT>
    > > >
    > > > Is there a way to clean-up or rewrite this select list before it is
    > > > published and remove the double entry using javascript?

    > >
    > > To clean up:
    > >
    > > -----------------------------------------
    > >
    > > <form>
    > > <select tabindex="1"
    > > name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    > > <option value="">(None)</option>
    > > <option value="8">name 1</option>
    > > <option value="10">name 2</option>
    > > <option value="11">name 1</option>
    > > </select>
    > > </form>
    > > <script type="text/javascript">
    > > var S =
    > > document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    > > while (S.options.length) S.options[0] = null;
    > > </script>
    > >
    > > -----------------------------------------
    > >
    > > To rewrite the options "without double entries":
    > >
    > > -----------------------------------------
    > >
    > > <form>
    > > <select tabindex="1"
    > > name="urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup">
    > > <option value="">(None)</option>
    > > <option value="8">name 1</option>
    > > <option value="10">name 2</option>
    > > <option value="11">name 1</option>
    > > </select>
    > > <input type=submit>
    > > </form>
    > > <script type="text/javascript">
    > > var N = new Object();
    > > var S =
    > > document.forms[0].elements['urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup'];
    > > while (S.options.length) {
    > > if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    > > S.options[0] = null;
    > > }
    > > for (i in N) S.options[S.length] = new Option(i,N);
    > > </script>
    > >
    > > -----------------------------------------
    > >
    > > I define "removing double entries" as "removing options with the same
    > > text" which is probably what you meant. The usual naming is <option
    > > value="[VALUE]">[TEXT]</option>. The criterium that is used to remove
    > > is not case sensitive.
    > >
    > > When deleting a double entry, the one that comes first is kept with its
    > > (albeit unique) value. If you want the last one to be kept, change
    > > if (!N[S.options[0].text]) N[S.options[0].text] = S.options[0].value;
    > > into
    > > N[S.options[0].text] = S.options[0].value;
    > >
    > > Do you really need a name as
    > > "urn:schemas-microsoft-com:eek:ffice:eek:ffice#CatLookup" for the select ? I
    > > would counsel to change it into something shorter and more
    > > alphanumericaloid.
    > >
    > > There is a syntax error in your code at the double >> (at </OPTION>>).
    > >
    > > Hope this helps,
    > >
    > > --
    > > Bart
     
    Beholder, Jan 22, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C Wilson
    Replies:
    1
    Views:
    375
    David Carlisle
    Dec 16, 2006
  2. Gumtree
    Replies:
    3
    Views:
    270
    Matt Kruse
    Nov 10, 2004
  3. sniper

    How to remove items of a select field

    sniper, Sep 19, 2006, in forum: Javascript
    Replies:
    2
    Views:
    101
    sniper
    Sep 19, 2006
  4. Samuel Murray
    Replies:
    3
    Views:
    156
    David Mark
    Feb 22, 2010
Loading...

Share This Page