Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2006, 04:00 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default drop down list opens dynamically when page loads

How do I cause a drop down list to open dynamically / automatically when the page loads?

I get as close as highlighting the first selection of the list but the list does not Drop down as needed.
ie: <BODY onload="formName.listName.focus();">

regards

 
Old April 18th, 2006, 06:38 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Robear!!
 It's not possible, I have tried to solve it ,yet looking for other alternatives too.
You can do it using dynamic layer ,but not through the select control as i have seen in many websites.

Plz let me know if you find the other alternatives.





Cheers :)

vinod
 
Old April 18th, 2006, 09:45 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

XMLHttpRequest

hi,

with XMLHttpRequest you can now post manually, I mean you don't need to have a form or anything. You can decide upon any data from Javascript and post it to your server...

This means that your 'form' elements can be anything, look like anything, and do anything that you can build with the help of javascript... XMLHttpRequest is cool...:D

To see how it works, get the sample code from Zakas' book http://www.wrox.com/WileyCDA/WroxTit...load_code.html here. Ok, don't know how that will look on the forum...Ok, apparently you can't hide the URL's...

Look for chapter 16 for code to make a cross-browser solution for it, and than you are rolling, have fun

ufo
 
Old April 19th, 2006, 02:25 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Ufo!!

 Robear question is to open the select box(dropdown list box) to be opened on page load.ie. without user click on the dropdown(selectbox) ,all the options for any given select box should be visible.
Which is not possible,without the user click on the select box.





Cheers :)

vinod
 
Old April 19th, 2006, 10:25 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear vinod,

what I am trying to say is that if you are hitting the ceiling by meeting restrictions in original html elements or other aspects of client side scripting languages for example, javascript is abstract and flexible enough to just replace them with your own objects in the DOM, which you can make do anything you want...

This means that it is maybe impossible to do this with a real html select element, but you could replace it with a select element you designed in javascript, maybe call it 'mySelect'. You than have that element look like a true select element (eg, a small table with no borders, one column, white background, lines of text, and so on, with two states, open and closed, with handlers to deal with the change and so forth...), and, have it open by a handler of the onload event of the body...

This implies however, that you have a custom element on the page that would not get posted when the form would be posted, because it would not be a form element... (although i think it would be possible by adding it to the forms node in the dom ... not entirely sure how exactly now, you need to experiment with these things a bit...)
That however is not a worry anymore since it is much more practical to take control entirely and ditch the form element... You just post manually with XMLHttpRequest and decide completely upon what elements supply information for your post. This way, opening a select box is only one of the many creative things you can do with 'form' elements...

By the way, saw that Nicolas C. Zakas published another book about this subject: Professional Ajax. (Stands for Asyncronous Javascript and XML)Have not read it yet, but I think it will be interesting if you are struggling with these things...
 
Old April 21st, 2006, 10:05 AM
ufo ufo is offline
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I found an even better way to do it... The problem is that if you get your results with XMLHttp, it doesn't end up in the browser history, and you can't specify a target for the return info. It just comes in the XMLHttpRequest object. This could be an annoying constraint. Probably the best way to get round it is just make hidden fields for the custom form elements, and then catch the submit attempt of the user, and place the values from your elements in the hidden fields, and then continue with traditional posting of the form....

have fun





Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Alert when page opens? larry Javascript How-To 19 July 6th, 2004 01:40 AM
Random News Topic when the page loads morpheus Classic ASP Databases 4 November 21st, 2003 01:38 PM
Generate a random article when page loads morpheus SQL Server ASP 1 October 28th, 2003 10:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.