section31 Posted March 10, 2004 Posted March 10, 2004 HI, does anyone know any other way for me to load up a page with a particular item selected from a drop down list besides doing this. Example shown in link: <option value="fiat"selected="selected">Fiat</option> http://www.w3schools.com/tags/tryit.asp?fi...tryhtml_select3 Thanks, Dave Quote
TCH-Bruce Posted March 10, 2004 Posted March 10, 2004 Acura Fiat Saab Volvo The above will create a dropdown list with Acura, Fiat, Saab, Volvo and Fiat will be selected. Does this help? Quote
HCSuperStores Posted March 10, 2004 Posted March 10, 2004 You can also use javascript to select something after your list is loaded. But I'm not sure if you're looking for this type of answer. Quote
section31 Posted March 10, 2004 Author Posted March 10, 2004 You can also use javascript to select something after your list is loaded. But I'm not sure if you're looking for this type of answer. Yes...I will need something after the list is loaded. Mind showing me the code. @TCH-Bruce Heh, thats pretty much the same thing...Not what I was looking for...thanks for the reply anyway. Quote
scotttyz Posted March 10, 2004 Posted March 10, 2004 Those would be the two ways that I know of. For the javascript something close to: ><script> Function DoThis() {yourformname.Auto_Name[optionname].select();} </script> <body onload(DoThis)> You woule have to "name" everthing for Javascript to find this i.e. <form action="" name="yourformname""....>, <option value="Acura"> Acura </option>, etc. If you wanted to have the form select an option depending on other input from another page, you could make the form page PHP. Pass a variable to the form page, then have php write that portion of the form. Quote
section31 Posted March 11, 2004 Author Posted March 11, 2004 LMAO good timing hu? Rock Sign Nice...thank you so much.... Where did you get this source if I may ask..any good sites for nitpicky stuff like this. the only site i usually use for javascript xhtml etc is w3schools.com. Its been adequate as a reference but I wouldn't mind using another one for other rare occassions. Quote
section31 Posted March 11, 2004 Author Posted March 11, 2004 Those would be the two ways that I know of. For the javascript something close to: ><script> Function doThis() {yourformname.Auto_Name[optionname].select();} </script> <body onload(doThis)> You woule have to "name" everthing for Javascript to find this i.e. <form action="" name="yourformname""....>, <option value="Acura"> Acura </option>, etc. If you wanted to have the form select an option depending on other input from another page, you could make the form page PHP. Pass a variable to the form page, then have php write that portion of the form. ok...I spoke to soon...I was sure i would be able to get your code to work but i was wrong...forgive my ignorance....can you help me out... can u implement your code on the sample form listed on this site. http://www.w3schools.com/tags/tryit.asp?fi...tryhtml_select3 The below didn't work. ><html> <script type="text/javascript" language="javascript" > <!-- function selectform() { testform.cars[audi].select(); } --> </script> <body onload(selectform)> <form name="testform"> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </form> </body> </html> Quote
HCSuperStores Posted March 11, 2004 Posted March 11, 2004 This is how you might select a car: <html> <body> <script> function selectform(carnum) { document.testform.cars.options[carnum].selected=1; } </script> <form name="testform"> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </form> <script> selectform(3); </script> </body> </html> With options, you have to treat them like arrays. The option count actually starts at 0, so even though "audi" is the 4th car, it's actually #3 in the list. The "volvo" would be #0. I use this kind of logic all the time in my programs when retrieving data from a database to populate a form with a list selection. Let me know if this is what you need. Send a PM to me if you want to get a quicker response from me. Good luck! Quote
scotttyz Posted March 11, 2004 Posted March 11, 2004 HC to the rescue! Thanks for cleaning up my code, have never acually used it to select it from a list. I learned something new Quote
section31 Posted March 11, 2004 Author Posted March 11, 2004 This is how you might select a car: <html> <body> <script> function selectform(carnum) { document.testform.cars.options[carnum].selected=1; } </script> <form name="testform"> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </form> <script> selectform(3); </script> </body> </html> With options, you have to treat them like arrays. The option count actually starts at 0, so even though "audi" is the 4th car, it's actually #3 in the list. The "volvo" would be #0. I use this kind of logic all the time in my programs when retrieving data from a database to populate a form with a list selection. Let me know if this is what you need. Send a PM to me if you want to get a quicker response from me. Good luck! Fantastic..I understand perfectly now. Thanks guys... So do you guys have any good sites to recommend to find little nitpicky stuff like this. Or are you just javascript gurus or what. Quote
scotttyz Posted March 11, 2004 Posted March 11, 2004 LOL Ask a lot of questions, I even changed my user name at a support site after a while because I asked so many. (got bashfull) I buy a good "for dummies book" to get started. I have Javascript, HTML, Perl etc for dummies. Then I get a good Bible, Que or Peachpit (or insert another) for the hard core stuff. For good sites: http://www.webmasterworld.com/ http://www.phpfreaks.com/forums Quote
HCSuperStores Posted March 11, 2004 Posted March 11, 2004 I use Javascript all the time. There's a book from O'Reilly that I reference all the time. In fact, I did it this time too ... just to be sure. Found I was using "option" when I should have been using "options". There's this other wierd thing that can happen too. You can accidentally try to reference a form before it's loaded. That's why the function for it is at the top, while the use for it is after the form. I suppose you could do the "onLoad" to cover this, but I've never found those trustworthy for some reason. Good luck with your project! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.