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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:57:03+00:00 2026-06-13T23:57:03+00:00

Any help on this would be MUCH appreciated! I am having a problem with

  • 0

Any help on this would be MUCH appreciated!

I am having a problem with this javascript code in IE and Safari only.

It works fine in other browser e.g firefox and chrome.

I believe in IE and Safari it’s not cycling through all the select option values correctly. e.g. in firefox there are two values for p, however in safari only 1 value.

JAVASCRIPT

<script type="text/javascript">
function selected(val, val1)
{
    var len = document.getElementById('attribute122').length;
    var p;
    for(p=0;p<len;p++)
    {
        if(document.getElementById('attribute122')[p].label == val1)
        {
            document.getElementById('attribute122').value = document.getElementById('attribute122')[p].value;
            document.getElementById('att_'+val).className = 'active';
        }
        else
        {
            if(document.getElementById('attribute122')[p].label !="Choose an Option...")
            {
                var chalpeveere = document.getElementById('attribute122')[p].label;
                // alert(chalpeveere);
                chalpeveere = chalpeveere.replace('.','_');
                // alert(chalpeveere);
                document.getElementById('att_' + chalpeveere).className = 'none';
            }
        }
    }
}

</script>

HTML

<div class="input-box">
<select id="attribute122" class="required-entry super-attribute-select" name="super_attribute[122]">
<option value="">Choose an Option...</option>
<option value="3" price="0">Medium</option>
</select>
</div>


<div class="Medium">
<a id="att_Medium" class="none" href="javascript:selected('Medium', 'Medium')"> </a>
</div>
  • 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-13T23:57:04+00:00Added an answer on June 13, 2026 at 11:57 pm

    Some comments:

    function selected(val, val1) {
        var len = document.getElementById('attribute122').length;
    

    Much better to store a reference to the element. If it’s a select element, its length is the number of options. It’s clearer to write it that way:

        var select = document.getElementById('attribute122');
        var len = select.options.length;
    

    But I wouldn’t set len here, see below.

    It’s much more common to use i, j, k, etc. as loop counters and to initialise them in the for expression. It’s common to set the limit here too:

        for (var i=0, len=select.options.length; i<len; i++) {
    
          if (select[p].label == val1) {
    

    Again, while you can access the options as properties of the select element, it’s clearer to access them via the options collection. Also, the label property is more commonly known as text, so:

          if (select.options[i].text == val1) {
    

    .

            document.getElementById('attribute122').value = document.getElementById('attribute122')[p].value;
    

    Setting the selected option by setting the value of the select element is also very new behaviour, it is far more common to set the option to selected:

            select.selectedIndex = i;
    

    or

            select.options[i].selected = true;
    

    .

            document.getElementById('att_'+val).className = 'active';
        }
        else
        {
            if(document.getElementById('attribute122')[p].label !="Choose an Option...")
            {
    

    Pesumably that is the first option, so you can just test:

            if (select.selectedIndex != 0) {
    

    .

                var chalpeveere = document.getElementById('attribute122')[p].label;
    

    becomes:

                var chalpeveere = select.optoins[i].text;
    

    .

                // alert(chalpeveere);
                chalpeveere = chalpeveere.replace('.','_');
                // alert(chalpeveere);
                document.getElementById('att_' + chalpeveere).className = 'none';
            }
          }
        }
      }
    

    So the tidied code becomes:

    function selected(val, val1) {
        var select = document.getElementById('attribute122'); 
        var options = select.options;
    
        for(var i=0, iLen=options.length; i<iLen; i++) {
    
            if (options[i].text == val1) {
                options[i].selected = true;
                document.getElementById('att_'+val).className = 'active';
    
            } else {
    
                if (select.selectedIndex != 0) {
                    var chalpeveere = options[i].text;
                    // alert(chalpeveere);
                    chalpeveere = chalpeveere.replace('.','_');
                    // alert(chalpeveere);
                    document.getElementById('att_' + chalpeveere).className = 'none';
                }
            }
        }
    }
    

    In the HTML:

    <a id="att_Medium" class="none" href="javascript:selected('Medium', 'Medium')">foo</a>
    

    If you want a button, use a button:

    <button id="att_Medium" class="none" onclick="
      selected('Medium', 'Medium')
    ">Set selected</button>
    

    or use a style span.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any help with this problem would be fantastic. I appreciate all contributions! Let us
Any help here would be greatly appreciated. I have this table hospital Nurse |
I would appreciate any help on this issue. Lets say I want to load
I'm relatively new to Java and would appreciate any help on this! I have
am trying to squeeze some performance out of this query, any help would be
By any chance you would be able to help optimize this query without me
Any help most appreciated, this is driving me insane. I'm doing exactly what I
I'm still grasping the basics of sql. Any help much appreciated. The table is
I am having a problem with some javascript that I wrote that is only
I'm having a weird problem with websync 4.0: it works fine on my local

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.