[PHPLondon-discuss] JQuery .attr
Alex V.
info at intoex.com
Mon Sep 24 10:13:34 BST 2007
Harry,
I've done it easier -
some_val = $('#element').attr('value') || ''
--
Alex
Monday, September 24, 2007, 11:45:58 AM, you wrote:
HR> You should be able to do something like the following which will
HR> distinguish between an undefined (null) value
HR> and an empty string.
HR> But yeah, this is tedious :\
HR> // --------------------------------------
HR> var some_val = $('#element').val();
HR> if( typeof(some_val) == "undefined" )
HR> {
HR> // Value is undefined
HR> } else
HR> {
HR> // Value is defined, but may be an empty string.
HR> }
HR> // --------------------------------------
>> -----Original Message-----
>> From: phplondon-discuss-bounces at lists.phplondon.org
>> [mailto:phplondon-discuss-bounces at lists.phplondon.org] On
>> Behalf Of Marcus Bointon
>> Sent: 23 September 2007 00:21
>> To: info at intoex.com; PHP London discussion list
>> Subject: Re: [PHPLondon-discuss] JQuery .attr
>>
>> On 22 Sep 2007, at 11:38, Alex V. wrote:
>>
>> > let i have <input id=element name=name type=text value=""
>> /> if I do
>> > $('#element').attr('value') - it returns "undefined"
>>
>> From the jquery docs I can see that the recommended way of
>> doing this is $('#element').val(). I don't know if that will
>> give you anything different, but it does seem odd that it
>> doesn't distinguish between undefined and an empty string.
>>
>> You're missing quotes around your attribute values, but you
>> probably knew that.
>>
>> Marcus
>> --
>> Marcus Bointon
>> Synchromedia Limited: Creators of
>> http://www.smartmessages.net/ UK resellers of info at hand CRM
>> solutions marcus at synchromedia.co.uk | http://www.synchromedia.co.uk/
>>
>>
>>
>> _______________________________________________
>> Phplondon-discuss mailing list
>> Phplondon-discuss at lists.phplondon.org
>> http://lists.phplondon.org/cgi-bin/mailman/listinfo/phplondon-discuss
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
More information about the Phplondon-discuss
mailing list