simple code for selecting matching text in a listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • .nLL

    simple code for selecting matching text in a listbox

    got below script, works fine with IE but fails on opera. my js knowledge is
    very limited and can't find whats wrong with it.

    ----------------------------------------------
    function selectMatching( x)
    {
    var S = document.getEle mentById("mymon th");
    var L = S.options.lengt h;
    for (var i=0; i <= L-1; i++)
    {
    if ((String(x.valu e).substring(0, 6)) ==
    String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
    }
    }
    -------------------------------------

    and i use it in below form

    -------------------------------------------------
    <form method="post" name="myform" action="default .asp">
    <p>
    Select Month: <select name="mymonth"
    onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
    <option value="20080401 " selected="selec ted" >April-2008 (25299)</option>
    <option value="20080301 " >March-2008 (2)</option>
    <option value="20080201 " >February-2008 (1)</option>
    </select>
    Day: <select name="myday" onChange="selec tMatching(this) ;">
    <option value="0" selected="selec ted">All days</option>
    <option value="20080401 " >1-Tuesday (1)</option>
    <option value="20080420 " >20-Sunday (2)</option>
    <option value="20080421 " >21-Monday (1)</option>
    <option value="20080425 " >25-Friday (25293)</option>
    <option value="20080427 " >27-Sunday (2)</option>
    </select>
    <input type="submit" value="View"/>
    </p>
    </form>
    ---------------------------------------------------



    what i do is. if user selects from months menu script resets days menu to
    all days (doesn't work on opera)

    if user changes days menu function finds matching month from the first list
    and selects it. Although days has 2 more numbers ad the end by substring i
    cut that part.

    can anyone offer another solution that would work on opera too without
    changing current form and its values?

    thanks


  • .nLL

    #2
    Re: simple code for selecting matching text in a listbox

    sdorted with
    -----------------------------------
    function selectMatching( x)
    {
    var S = document.myform .elements['mymonth'];
    var L = S.options.lengt h;
    for (var i=0; i <= L-1; i++)
    {
    if ((String(x.valu e).substring(0, 6)) ==
    String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
    }
    }

    and

    function setContent() {
    if(document.det ailsform.paymen tMethod.value== "1")
    {
    document.getEle mentById('payme ntMethodExplain ').innerHTML= "Registered
    Paypal e-mail:";
    }
    if(document.det ailsform.paymen tMethod.value== "2")
    {
    document.getEle mentById('payme ntMethodExplain ').innerHTML= "Bank account
    details:";
    }
    if(document.det ailsform.paymen tMethod.value== "3")
    {
    document.getEle mentById('payme ntMethodExplain ').innerHTML= "Full name and
    address:";
    }
    }




    ".nLL" <noone@here.com wrote in message
    news:KpoRj.1111 53$fx2.51538@ne wsfe08.ams2...
    got below script, works fine with IE but fails on opera. my js knowledge
    is very limited and can't find whats wrong with it.
    >
    ----------------------------------------------
    function selectMatching( x)
    {
    var S = document.getEle mentById("mymon th");
    var L = S.options.lengt h;
    for (var i=0; i <= L-1; i++)
    {
    if ((String(x.valu e).substring(0, 6)) ==
    String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
    }
    }
    -------------------------------------
    >
    and i use it in below form
    >
    -------------------------------------------------
    <form method="post" name="myform" action="default .asp">
    <p>
    Select Month: <select name="mymonth"
    onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
    <option value="20080401 " selected="selec ted" >April-2008 (25299)</option>
    <option value="20080301 " >March-2008 (2)</option>
    <option value="20080201 " >February-2008 (1)</option>
    </select>
    Day: <select name="myday" onChange="selec tMatching(this) ;">
    <option value="0" selected="selec ted">All days</option>
    <option value="20080401 " >1-Tuesday (1)</option>
    <option value="20080420 " >20-Sunday (2)</option>
    <option value="20080421 " >21-Monday (1)</option>
    <option value="20080425 " >25-Friday (25293)</option>
    <option value="20080427 " >27-Sunday (2)</option>
    </select>
    <input type="submit" value="View"/>
    </p>
    </form>
    ---------------------------------------------------
    >
    >
    >
    what i do is. if user selects from months menu script resets days menu to
    all days (doesn't work on opera)
    >
    if user changes days menu function finds matching month from the first
    list and selects it. Although days has 2 more numbers ad the end by
    substring i cut that part.
    >
    can anyone offer another solution that would work on opera too without
    changing current form and its values?
    >
    thanks
    >
    >

    Comment

    • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

      #3
      Re: simple code for selecting matching text in a listbox

      ..nLL escribió:
      got below script, works fine with IE but fails on opera. my js knowledge
      is very limited and can't find whats wrong with it.
      It doesn't work in Firefox either. So I'd say it only works in IE.

      var S = document.getEle mentById("mymon th");
      This line finds an HTML tag with id="mymonth". There isn't any on the
      page. Replace it with:

      var S = document.forms["myform"].mymonth;

      This way you call a form element with name "mymonth" in a form with name
      "myform":
      <form method="post" name="myform" action="default .asp">
      <p>
      Select Month: <select name="mymonth"
      Same here:
      onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
      onChange="docum ent.forms['myform'].myday.selected Index=0"


      --
      -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      -- Mi sitio sobre programación web: http://bits.demogracia.com
      -- Mi web de humor al baño María: http://www.demogracia.com
      --

      Comment

      Working...