473,394 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dropdown Box Onclick

384 256MB
What I'm trying to do i think is with javascript, i have a site in PHP and when a user logs in i want them to see the little tab with the downwards arrow, when the click on this a box will appear and display the users avatar and username etc and an upwards arrow, when the user clicks on this upwards arrow then the box disappears back up and only shows the tab with the downwards arrow.

I've been working with PHP & mySQL for over 7 years now but near really used javascript till now, any help is well appreciated. Thanks in advance.

ImageShack - Image Hosting :: examplenc8.jpg
Dec 12 '08 #1
13 5134
acoder
16,027 Expert Mod 8TB
To show something hidden onclick, change the style.display property to "block". You should have it set to "none" initially to keep it hidden. Of course, to hide it again, set it back to none:
Expand|Select|Wrap|Line Numbers
  1. <div id="divObj" style="display:none">
Expand|Select|Wrap|Line Numbers
  1. // show
  2. document.getElementById("divObj").style.display = "block";
  3. // hide
  4. document.getElementById("divObj").style.display = "none";
Dec 12 '08 #2
ziycon
384 256MB
Thanks for that, this wont make it gradually appear and gradually disappear though, will it?
Dec 12 '08 #3
ziycon
384 256MB
Ok, I've played around with it and I'm stumped, i have this code below on my page:
Expand|Select|Wrap|Line Numbers
  1. <div id="header_profile_details" style="display:none;"></div>
  2. <div id="header_profile_tab"><a href="#" OnClick=\'(this);\'>down</a></div>
The CSS for these DIV's is:
Expand|Select|Wrap|Line Numbers
  1. #header_profile_tab { 
  2.     float: right;
  3.     width: 60px;
  4.     height: 20px;
  5.     margin: 0 10px 0 0;
  6.     font-size: 14px;
  7.     font-weight: bold;
  8.     background-color: #FF0000;
  9.     text-align: center;
  10.     clear: right;
  11.     display: inline;
  12. }
  13. #header_profile_details { 
  14.     float: right;
  15.     width: 100px;
  16.     height: 60px;
  17.     margin: 0 10px 0 0;
  18.     font-size: 14px;
  19.     font-weight: bold;
  20.     background-color: #FF0000;
  21.     text-align: center;
  22.     clear: right;
  23. }
Not sure what to do next!??
Dec 12 '08 #4
acoder
16,027 Expert Mod 8TB
@ziycon
For that, you will need timing via the setInterval or setTimeout methods.
Dec 12 '08 #5
acoder
16,027 Expert Mod 8TB
@ziycon
Since you're using CSS, you dont need to declare the style inline, so add "display:none to the style declaration for header_profile_details.

In the down link, you need to call a function, e.g.
Expand|Select|Wrap|Line Numbers
  1. <div id="header_profile_tab"><a href="#" onclick="show('header_profile_details'); return false;">down</a></div>
Then in the javascript:
Expand|Select|Wrap|Line Numbers
  1. function show(id) {
  2.     document.getElementById(id).style.display = 'block';
  3. }
Dec 12 '08 #6
ziycon
384 256MB
Got it working now, another little question, how would i go about changing the option from down to display up and call a hide function when the box is displayed?

Sorry about all the questions, I'm not up on JS. Thanks for all your help.
Dec 12 '08 #7
acoder
16,027 Expert Mod 8TB
You can use a show/hide function which checks whether it's showing or hidden and then does both jobs: shows/hides appropriately and changes the display text:
Expand|Select|Wrap|Line Numbers
  1. function showhide(id) {
  2.     var details = document.getElementById(id);
  3.     if (details.style.display == "block") {
  4.         // change it to "none"
  5.         ...
  6.         // and change link text
  7.         document.getElementById("link").innerHTML = "down";
  8.     } else {
  9.         // similar for the opposite
  10.     }
  11. }
Dec 12 '08 #8
ziycon
384 256MB
Sorry, could you explain that cause i don't really understand it!?
Dec 12 '08 #9
ziycon
384 256MB
Got it sorted, working fine now, thanks for all your help acoder!
Dec 12 '08 #10
ziycon
384 256MB
Another add-on question for this, how would i go about say the user clicks down and shows the box, how would i keep that box open across the site on different pages without it closing everytime i go to a new page?
Dec 13 '08 #11
acoder
16,027 Expert Mod 8TB
You could use a cookies (link).
Dec 13 '08 #12
ziycon
384 256MB
I code use sessions in the same way couldn't i as the site already has a session from when you log in.
Dec 13 '08 #13
acoder
16,027 Expert Mod 8TB
You could, but since this happens client-side, you will need to pass this information on to the server-side through some means, e.g. Ajax, form posting, URL, open new window, iframe, etc.
Dec 13 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
20
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
3
by: Jon | last post by:
I am using cascading dropdowns, where the selection in one determines what fills another. In regular ASP I simply loaded a giant dataset into javascript array and when you clicked on one dropdown,...
2
by: Sreenath Rao Nellutla | last post by:
Hai all, I am trying to create dropdown calendar control with HTML input control by writing JavaScript. But while executing I am getting the error as "Error on Page" on the status bar of the...
5
by: John Grandy | last post by:
I wrote a function to populate my dropdowns on the client-side. The function adds <optionelements to the <selectonly if none are initially present. I call the population function from either...
2
by: bdbeames | last post by:
Ok, It has been one of those days. Here is my bump in the road. I have an add user form for the administrator. The administrator enters name, password and then selects access level from a...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
2
coolv
by: coolv | last post by:
Hello I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me. Below is my code. thanks.............. <?php ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.