Jump to content

[SOLVED] Simple problem


waynew

Recommended Posts

I've a select box that allows the user to choose how many file attachments they want to add. So, say for example they choose the option "2", 2 file fields will appear, courtesy of

 

style.display = "table-row";

 

(File fields are located in table rows).

 

Works fine in FF, but throws up an error and doesn't work in IE7. The error is "Could not get the display property. Invalid argument.

 

The html:

<select name="attachments" id="attachments" onchange="return show_hide_uploadfields(this.value)">
        <option value="0" selected="selected">0</option>
         <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
    </select>

 

The JS is:

 

function show_hide_uploadfields(num){
    
    //hide all fields first
    var i = 1;
    while(i < 6){
        var id = "file" + i;
        document.getElementById(id).style.display = 'none';
        i++;
    }
    
    //show number user wants
    var i = 1;
    while(i <= num){
        var id = "file" + i;
        document.getElementById(id).style.display = 'table-row';
        i++;
    }
}

 

An example of my table row html:

<tr id="file1" style="display:none;">

Link to comment
Share on other sites

Just set the dsplay value to an empty string and the browser will display it as it you hadn't set any display value to begin with.

 

Also, that function could be written much more simply

function show_hide_uploadfields(num)
{
    var idx = 1;
    while(document.getElementById('file'+idx))
    {
        var displayValue = (idx<=num)?'':'none';
        document.getElementById('file'+idx).style.display = displayValue;
        idx++;
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.