Re: New way to make select boxes auto select

From: Date: Fri, 26 Jul 2002 14:25:59 +0000
Subject: Re: New way to make select boxes auto select
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109718@lists.php.net to get a copy of this message
I use javascript for that! :) <script> function select_lb_by_value(lb, val) { len = lb.options.length; for (i=0;i<len;i++) if (lb[i].value == val) { lb.selectedIndex = i; break; } } </script> then I call this: <script> select_lb_by_value(document.form1.selectbox1, '<?=$selectbox1?>'); </script> fast and simple, //elias "Nathan Cook" <ncook@pcsedu.com> wrote in message news:001e01c233f9$46f91f00$1500a8c0@pcsedu.com... > You may already be doing it like this, but I think I found a new way to > make select boxes auto-select (what data they put in) a lot easier. All you > have to do is put a variable in each select tag that is equal to the value > of the select option i.e.: <option value=teacher $teacher> -- then all you > have to do is base the variable on that <select name=interest> $$interest = > "selected"; quick and easy with out having to loop through an if elseif > statement. Let me know if you like that method or have any objections. > > Full example below. > > print("<select name=interest>\n"); > // creates a variable with a name based on > // the value of interest with a value of "selected" > $$interest = "selected"; > print("<option value=>- Select One -</option>\n"); > print("<option value=teacher $teacher>Teacher</option>\n"); > print("<option value=lego $lego>Lego Enthusiast</option>\n"); > print("<option value=student $student>Student</option>\n"); > print("<option value=homeschool $homeschool>Homeschool Parent</option>\n"); > print("<option value=browsing $browsing>Browsing</option>\n"); > print("<option value=afterschool $afterschool>Afterschool</option>\n"); > print("<option value=bgca $bgca>Boys & Girls Club</option>\n"); > print("<option value=ymca $ymva>YMCA</option>\n"); > print("</select>&nbsp;&nbsp;\n"); > > [ Nathan Cook | ncook@pcsedu.com ] > >

« previous php.general (#109718) next »