[PHPLondon-discuss] JQuery .attr
Harry Roberts
harry at telappliant.com
Mon Sep 24 09:45:58 BST 2007
You should be able to do something like the following which will distinguish between an undefined (null) value and an empty string.
But yeah, this is tedious :\
// --------------------------------------
var some_val = $('#element').val();
if( typeof(some_val) == "undefined" )
{
// Value is undefined
} else
{
// Value is defined, but may be an empty string.
}
// --------------------------------------
> -----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