SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    "Invalid assignment left-hand side"

    Hi, the Firefox javascript console is telling me I have this error. The script does work, however.
    Code:
      
        var sel = document.getElementsByName('perpage')[0];
        var inp = document.getElementsByName('custom')[0];
        if (sel) {
          sel.onchange = function() {
            if (sel.value === 'custom') {
              inp.style.display = 'inline';
              inp.disabled = false;
              inp.focus() = true;
            } // it's this line Firefox says the error is on
            else {
              inp.style.display = 'none';
              inp.disabled = true;
            }
          }
        }
    I see nothing that can possibly be wrong. Can you?

  2. #2
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    inp.focus() = true;

    you are calling the focus function when you add the brackets () on the end, so that is why you cant assign there.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Duh. So it's just inp.focus();

    Should have thought of that.

    Cheers Mr Money.

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Back to this problem... IE6 doesn't like this:
    Code:
      if (sel) {
        sel.onchange = function() {
          if (sel.value === 'custom') {
            inp.className = 'show';
            inp.disabled = false;
            inp.focus();
          }
    sel is a dropdown, inp is a text input. Firefox/Opera works fine, IE6 doesn't give the input focus and throws this error:

    Can't move focus to the control because it is invisible, not enabled, or of type that does not accept the focus.

    It's visible (the class 'show' changes its display value to 'inline'), it obviously isn't disabled and I'm pretty sure text inputs accept focus.

    The only other thing I can think of is to use try{ } to suppress the error from occurring in IE, but ideally I'd like the focus() to work.

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Possibly sel.value should be sel.options[sel.selectedIndex].text for IE.

    firefox reads the value as the text of the selected option if the option has NO value attribute-
    but sometimes options have values and text- its good to specifically call for the one you want.

    And you have to use .text in IE, unless it is a value you are looking for.
    Last edited by mrhoo; Feb 13, 2007 at 20:59.

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid it doesn't work. The options have values and text and using both methods works in IE6 and Firefox. The only problem is that the inp.focus(); bit doesn't work in IE6. The class gets changed to .show and inp gets enabled - but it isn't focused.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •