Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

jquery-val-method-throwing-error

#174

On Thu, Jul 1, 2010 at 9:58 PM, Dylan Just dylan.just@ephox.com wrote:

Hi John,

Sorry to trouble you, wonder if you could help.

I've found an issue in Envjs, but I'm unable to sign up to the Lighthouse issue tracking system - I get a server error.

The issue is when using jquery's .val() method on select tags, when using Envjs. The following code demonstrates it:

var x = $('<select><option value="value1">text1</option><option

value="value2" selected="selected">text2');

print(x.val());
print(x.get(0).value);

The first one prints "text2", the second prints "value2".

We've tracked it down to this section of jQuery's val method:

    if ( jQuery.nodeName( elem, "option" ) ) {
            return (elem.attributes.value || {}).specified ? elem.value

: elem.text;

    }

For some reason, elem.attributes.value is not set by Envjs - it works fine in a browser. It only seems to affect option elements created like above. If I create the options using $("").attr("value", "myvalue"); it seems to be fine.

Would really appreciate if you could look into this, or pass off to someone else on the Envjs team to look at.

Many thanks,

Dylan Just Ephox

Reported by Thatcher · July 2nd, 2010 @ 07:30 AM

State: new
Milestone: none
Assigned to: Thatcher Thatcher

Activity

  1. Gabriel Jürgens
    Gabriel Jürgens
    • Assigned user set to Thatcher
    • Tag changed from jquery val to jquery val, htmloptionelement

    Hi! I think i'm having a problem related with this issue, but without using jQuery.

    Here is an example that throws a "Cannot find function add" error when running in Rhino:


    <option value="1">One</option>
    

    //JavaScript var oSelect = document.getElementById('oSelect');
    var oOption = document.createElement('OPTION');
    // Add the option to the collection first, then set properties oSelect.options.add(oOption);
    oOption.innerHTML = "Two";
    oOption.value = "2";

    I will try to make some more debugging and see if I can give you more info about this issue.

    Thanks for your great work, and sorry about my bad english!
    Gabriel

    September 2nd, 2010 @ 04:56 AM

  2. Gabriel Jürgens
    Gabriel Jürgens

    Sorry about my previous post!

    I'm a newie using lighthouse, and didn't saw the code snipplet, so here is again:

    <select id="oSelect">
    </select>
    
    <script type="text/javascript">
    var oSelect = document.getElementById('oSelect');
    
    oSelect.options[0] = new Option("ONE",1);
    oSelect.options[1] = new Option("TWO",2);
    
    alert(oSelect.options[1].value);
    
    </script>
    

    when I run this at Rhino using "env.rhino.js", I get this error:

    [  Envjs/1.6 (Rhino; U; Windows XP x86 5.1; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]
    error loading script  [object HTMLScriptElement]   TypeError: Cannot read property "value" from undefined
    

    This example runs fine on Firefox, IE7, IE6, and Chrome, so I think it's an Envj issue.

    Sorry about my previous post!
    Thanks,
    Gabriel

    September 2nd, 2010 @ 11:27 AM

  3. Thatcher
    Thatcher

    Thanks Gabriel,
    I'll integrate this into our unit tests and track down the issue. I expect
    it will be relatively easy to find given the good test case!
    Thatcher

    September 22nd, 2010 @ 04:19 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.