NYCPHP Meetup

NYPHP.org

[nycphp-talk] Trapping JS errors in function called onSubmit

Kristina Anderson ka at kacomputerconsulting.com
Wed May 7 11:25:46 EDT 2008


PS special thanks to Tedd for testing the script for me.

Also, I've forwarded this thread to the person who designed the HTML 
forms for this project.

Is there any reason to prefer label tags over using id, or is either 
one fine going forward?

--Kristina

> Hi everyone -- thanks again for help and just wanted to let you know 
> what the issue ended up being.
> 
> If a label tag with for= is not used, then name= & id= must both be 
> used inside the <INPUT> tag, as Javascript uses id & PHP uses name.
> 
> 
> 
> --  Kristina
> 
> > ed,
> > 
> > it calls the subfunctions like so:
> >   reason += validateUsername(theForm.user_name);
> >   reason += validatePassword(theForm.pwd);
> >   reason += validateEmail(theForm.email1);
> >   reason += validatePhone(theForm.phone1);
> >   reason += validateEmpty(theForm.first_name);
> > 
> > which appears to be OK
> > 
> > > Well that's different... if the Javascript is 'looping' over the 
> form 
> > > array as so:
> > > 
> > > <script language="javascript">
> > > function check(){
> > > fld = document.getElementById('test').value.length ;
> > > alert(fld);
> > > }
> > > function loopForms(){
> > > var frms = document.forms ;
> > > for(a=0;a<frms.length;a++){
> > > alert(frms.item(a).name);
> > >     for(b=0;b<frms.item(a).elements.length;b++){
> > >         frm = frms.item(a);
> > >         alert(frm.elements.item(b).value);       
> > >     }
> > > }
> > > }
> > > </script>
> > > 
> > > And there isn't a check for the type, then the 'blanks' you're 
> seeing 
> > > are buttons.
> > > 
> > > 
> > > Kristina Anderson wrote:
> > > > it's implicitly referenced, i.e. the name of the element is 
being 
> > > > passed in as an enumerated value assigned to the type of 
> validation 
> > > > subroutine I want to call for that element.
> > > >
> > > > But by "by id" i guess that there needs to be an 
id="sameasname" 
> in 
> > > > each form element...?? That could be the issue?
> > > >
> > > > --Kristina
> > > >
> > > >   
> > > >> That's correct Javascript, assuming that fld = 
> > > >> document.getElementById('the element you are referencing')
> > > >>
> > > >> Kristina Anderson wrote:
> > > >>     
> > > >>> if (fld.value.length == 0) {
> > > >>>
> > > >>>
> > > >>> is that even right?  
> > > >>>
> > > >>> I thought it used to be fld.length or fld.text.length...??
> > > >>>
> > > >>>
> > > >>> Kristina
> > > >>>
> > > >>>
> > > >>>   
> > > >>>       
> > > >>>> Rolan,
> > > >>>>
> > > >>>> I found this one that looked very easy to expand at
> > > >>>>
> > > >>>> http://www.webcheatsheet.com/javascript/form_validation.php
> > > >>>>
> > > >>>> However it is not picking up the blank fields...
> > > >>>>
> > > >>>> I can try yours if you point me to it!
> > > >>>>
> > > >>>> I need something that is extensible to handle the various 
> types 
> > of 
> > > >>>> input like emails, phone numbers, etc. 
> > > >>>>
> > > >>>> -- Kristina
> > > >>>>
> > > >>>>
> > > >>>>     
> > > >>>>         
> > > >>>>> which one are you using? FormChek.js is easy and hasn't let 
> me 
> > > >>>>>           
> > > > down 
> > > >   
> > > >>>>>       
> > > >>>>>           
> > > >>>> yet.
> > > >>>>     
> > > >>>>         
> > > >>>>> ~Rolan
> > > >>>>> _______________________________________________
> > > >>>>> New York PHP Community Talk Mailing List
> > > >>>>> http://lists.nyphp.org/mailman/listinfo/talk
> > > >>>>>
> > > >>>>> NYPHPCon 2006 Presentations Online
> > > >>>>> http://www.nyphpcon.com
> > > >>>>>
> > > >>>>> Show Your Participation in New York PHP
> > > >>>>> http://www.nyphp.org/show_participation.php
> > > >>>>>
> > > >>>>>       
> > > >>>>>           
> > > >>>> _______________________________________________
> > > >>>> New York PHP Community Talk Mailing List
> > > >>>> http://lists.nyphp.org/mailman/listinfo/talk
> > > >>>>
> > > >>>> NYPHPCon 2006 Presentations Online
> > > >>>> http://www.nyphpcon.com
> > > >>>>
> > > >>>> Show Your Participation in New York PHP
> > > >>>> http://www.nyphp.org/show_participation.php
> > > >>>>
> > > >>>>
> > > >>>>     
> > > >>>>         
> > > >>> _______________________________________________
> > > >>> New York PHP Community Talk Mailing List
> > > >>> http://lists.nyphp.org/mailman/listinfo/talk
> > > >>>
> > > >>> NYPHPCon 2006 Presentations Online
> > > >>> http://www.nyphpcon.com
> > > >>>
> > > >>> Show Your Participation in New York PHP
> > > >>> http://www.nyphp.org/show_participation.php
> > > >>>
> > > >>>
> > > >>>   
> > > >>>       
> > > >> _______________________________________________
> > > >> New York PHP Community Talk Mailing List
> > > >> http://lists.nyphp.org/mailman/listinfo/talk
> > > >>
> > > >> NYPHPCon 2006 Presentations Online
> > > >> http://www.nyphpcon.com
> > > >>
> > > >> Show Your Participation in New York PHP
> > > >> http://www.nyphp.org/show_participation.php
> > > >>
> > > >>     
> > > >
> > > > _______________________________________________
> > > > New York PHP Community Talk Mailing List
> > > > http://lists.nyphp.org/mailman/listinfo/talk
> > > >
> > > > NYPHPCon 2006 Presentations Online
> > > > http://www.nyphpcon.com
> > > >
> > > > Show Your Participation in New York PHP
> > > > http://www.nyphp.org/show_participation.php
> > > >
> > > >
> > > >   
> > > 
> > > _______________________________________________
> > > New York PHP Community Talk Mailing List
> > > http://lists.nyphp.org/mailman/listinfo/talk
> > > 
> > > NYPHPCon 2006 Presentations Online
> > > http://www.nyphpcon.com
> > > 
> > > Show Your Participation in New York PHP
> > > http://www.nyphp.org/show_participation.php
> > > 
> > > 
> > 
> > _______________________________________________
> > New York PHP Community Talk Mailing List
> > http://lists.nyphp.org/mailman/listinfo/talk
> > 
> > NYPHPCon 2006 Presentations Online
> > http://www.nyphpcon.com
> > 
> > Show Your Participation in New York PHP
> > http://www.nyphp.org/show_participation.php
> > 
> > 
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 




More information about the talk mailing list