How do I stop my JS from erring if I call an element that does not exist. I have a form that is dynamically generated on the server (PHP) I have a script that calls $F(''foobar'') but it might be the case that that field does not exist. I tried doing if($F(''foobar'')) But even that throws an error.. Thanks.. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Answering myself.. use if($(''foobar'')) Not $F(''foobar'') :-) ______________________________________________________________________ Alex Duffield On 23-May-07, at 1:54 PM, Alex Duffield wrote:> > How do I stop my JS from erring if I call an element that does not > exist. > > I have a form that is dynamically generated on the server (PHP) > > I have a script that calls $F(''foobar'') but it might be the case that > that field does not exist. > > I tried doing > > if($F(''foobar'')) > > But even that throws an error.. > > Thanks.. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Alex Duffield wrote:> How do I stop my JS from erring if I call an element that does not > exist. > > I have a form that is dynamically generated on the server (PHP) > > I have a script that calls $F(''foobar'') but it might be the case that > that field does not exist.Don''t use $F. That''s the way it''s designed to behave. Just use $() instead. if( $(''foobar'') ) { var value = $(''foobar'').value; } -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks boss, that thought occurred to me just as I hit the send button!! ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com On 23-May-07, at 1:56 PM, Michael Peters wrote:> > Alex Duffield wrote: >> How do I stop my JS from erring if I call an element that does not >> exist. >> >> I have a form that is dynamically generated on the server (PHP) >> >> I have a script that calls $F(''foobar'') but it might be the case that >> that field does not exist. > > Don''t use $F. That''s the way it''s designed to behave. Just use $() > instead. > > if( $(''foobar'') ) { > var value = $(''foobar'').value; > } > > -- > Michael Peters > Developer > Plus Three, LP > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---