Getting value of form element with .value is empty using .submit() #46

Closed
liamgooding opened this Issue Aug 15, 2011 · 5 comments

Comments

Projects
None yet
2 participants

using the .submit() listener for a form

x$('#form-id').submit(function(){
    console.log(document.getElementById('input-id').value);  // correctly gets value
    console.log(x$('#input-id').attr('value'));  // gives undefined
    console.log(x$('#input-id').value);  // gives undefined
});
Owner

filmaj commented Aug 29, 2011

Can you post the markup, or show full code for a test? What kind of element is it with id "input-id"?

@ghost

ghost commented Sep 1, 2011

I can confirm this issue, but I only tested this on the Android emulator.

Javascript:
x$("#buttont").click(function (element) {
alert(x$("#p").attr("value"));
});

Html 1:
<input type="password" id="p" name="p" />

Html 2:
<input type="password" id="p" name="p" value="test" />

When run with "Html 1", always returns an empty string (""). When run with "Html 2", always returns "test", no matter if the values in the field has changed.

Owner

filmaj commented Sep 1, 2011

Thank you, I'll check this out as soon as I get a chance

@ghost

ghost commented Oct 28, 2011

I get this problem on mobile safari and chrome because the "tagName" of the element returned by x$('#button') is "INPUT" and not what the code is == to "input".

$ diff xui-2.2.0.js xui-2.2.0-mod.js 
555c555
<                 if (el.tagName == 'input' && attribute == 'value') el.value = val;
---
>                 if (el.tagName.toLowerCase() == 'input' && attribute == 'value') el.value = val;
564c564
<                 if (el.tagName == 'input' && attribute == 'value') attrs.push(el.value);
---
>                 if (el.tagName.toLowerCase() == 'input' && attribute == 'value') attrs.push(el.value);
Owner

filmaj commented Oct 28, 2011

Now fixed in 1f2cdda - also added specs for this. Thanks guys!

filmaj closed this Oct 28, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment