View Full Version : simple (i hope) javascript question...
section8ight
02-17-2004, 01:06 PM
http://taxdebtsolutions.com
if you look at the box on the left near the header, it's kind of a quick nav to jump around the site (the 'your solutions start here' area). For some reason our client wants the "make a selection" line taken out, and just have the first option show up as a default. However when i do this, the first option is completely inactive, which makes it impossible to click it. How would i go about making the first item an active link in the list?
splict
02-17-2004, 01:29 PM
I think the problem is that the function for dropdown nav's are called 'onChange' This means that in order to call the function you have to choose something different than what is selected. So if the first item is selected by default then you can't pick the first item without picking something else first.
What I have done to get around this is to use a server-side script to insert 'SELECTED' into the option of whatever page I am at. This way when someone goes to 'about.html' About will be the selected entry in the option box. Then all of the buttons except about will be available - and they won't need about because they are already there.
Unfortunately I think your site is in html and if you don't have access to server side scripting then this won't help :( unless you want to rely on javascript - it might be possible.
section8ight
02-17-2004, 01:31 PM
my server is php ready, and we use simple mail forms for it.. however i am not good with php, and probably would not be able to go about figuring out how to do it. Is there a different function besides onChange that would work?
splict
02-17-2004, 01:43 PM
Not to say there isn't another solution out there, but, I'm pretty sure onChange is the only reliable event for select boxes.
The php would be fairly trivial to write and you could do it in one file including the form and then just include that external file in each of your pages. What would be the bigger pain and potential problem causer is changing all of your links since any page that had that select box would need to be a .php file in order for it to work properly.
It just seems like a change that is not worth the many complications. :( If you still wanted to do it, though, I could help you figure out the php, but I would recommend against it. Hopefully someone else knows of another way.
section8ight
02-17-2004, 01:47 PM
i don't want to do it.. but the client does; and it's bad business to tell them we won't do something (that and it's billable hours, so I'm not complaining too much). Any help you could offer, even if just serving up the php form you used would be infinitely appreciated.
splict
02-17-2004, 02:27 PM
Yeah, I know how it is with clients. :rolleyes: And I certainly wouldn't argue with billable hours, right now. So, here you go:
This is the sample page with a sample javascript function to change the page. This would be your home.php about.php etc. The php line just includes our form/drop down box. Note: Make sure you change 'scrip t' to 'script' the forum wouldn't let me post unless I changed it.
<scrip t LANGUAGE="javascript">
function changePage()
{
var number = document.DropDown.DDlinks.selectedIndex;
location.href = document.DropDown.DDlinks.options[number].value;
}
</SCRIPT>
<?php include('nav.php'); ?>
This is your nav.php file:
<?php
$c_page = $_SERVER['PHP_SELF']; // gets the current path and filename
$c_page = basename($c_page, ".php"); // strip it so we have just the filename - no extention
$sel[$c_page]='selected'; // place the value 'selected' in the $sel array at the index of our filename
// below, in the option area we echo the value of $sel at that index. it will not echo anything if it doesn't exist
// if it exists, because we just set it, it will echo 'selected' making that box selected.
?>
<FORM NAME="DropDown">
<SELECT NAME="DDlinks" onChange="changePage(this.form)" >
<OPTION VALUE="home.php" <?=$sel['home'] ?> > Home
<OPTION VALUE="contact.php" <?=$sel['contact'] ?> > Contact
<OPTION VALUE="about.php" <?=$sel['about'] ?> > About
</SELECT>
</FORM>
It strips the file name from 'www.mydomain.com/home.php' to 'home'. Then it puts 'selected' as the value in $sel['home']. then we echo the values out in the form. The one that we previously set (based on the current filename) will echo 'selected' therefore making that item the default selected page. Maybe not the most elegant solution, but certainly fairly simple. Just ask, if you have some questions - I don't know how well I explained it. I included a sample setup with 3 pages.
-splict
section8ight
02-17-2004, 02:33 PM
thanks so much splict... I appreciate all the help
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.