Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 03-25-2010, 10:47 AM   #1
New Member
 
Join Date: Feb 2010
Posts: 10
Post javascript and drop down lists

I'm trying to assign a behaviour to a drop down list.

Been fiddling with it for a long time now and can't get it to work......ARHG!

I have pasted the relevant html javaSript below!

Please can somebody tell me where i have gone wrong?

html.......

<select name="eachSegment" id="eachSegment">
<optgroup label = "Segments">
<option value="segment1">Segment1</option>
<option value="segment2">Segment2</option>
<option value="segment3">Segment3</option>
<option value="segment4">Segment4</option>
<option value="segment5">Segment5</option>
<option value="segment6">Segment6</option>
<option value="segment7">Segment7</option>
<option value="segment8">Segment8</option>
<option value="segment9">Segment9</option>
<option value="segment10">Segment10</option>
</optgroup>
</select>

JS......

var $ = function (id) { return document.getElementById(id);}

var segSegment = function() {

if (eachSegment == "segment1") {
alert ("1");
} else if (eachSegment == "segment2"){
alert("2");

} else if (eachSegment == "segment3"){
alert("3");

} else if (eachSegment == "segment4"){
alert("4");

} else if (eachSegment == "segment5"){
alert("5");

} else if (eachSegment == "segment6"){
alert("6");

} else if (eachSegment == "segment7"){
alert("7");

} else if (eachSegment == "segment8"){
alert("8");

} else if (eachSegment == "segment9"){
alert("9");

} else if (eachSegment == "segment10"){
alert("10");

} else {
alert("please select a segment");
}
}
window.onLoad = function () {
$("eachSegment").onchange = segSegment;
}

Last edited by kasio99; 03-25-2010 at 02:25 PM.
kasio99 is offline   Reply With Quote


Old 03-25-2010, 03:23 PM   #2
Super Moderator
 
Join Date: Oct 2008
Location: Arizona, USA
Posts: 1,053
Default

I am not an expert at javascript, however, when i have written functions and variables they look like this:

Code:
function myJsFunction(obj) { 
       /* statement */
}
 
$(obj).click(function() { 
      /* statement */
});

var myNewObj =  /* blah blah */
Have you considered using css for the drop down menu instead of entirely javascript?
__________________
John Darling
Graphic / Web Designer
SmarterTools Inc.
(877) 357-6278
www.smartertools.com
PixelPusher is offline   Reply With Quote
Old 03-25-2010, 04:51 PM   #3
Bronze Member
 
Join Date: Mar 2010
Location: Norfolk, UK
Posts: 78
Default

You might be better off having a search for a premade drop down menu script (sometime called an accordian menu) - there are plenty out there, Jquery ones will have animations in them as well.
__________________
Website Design in Norfolk
Twitter
craftygeek is offline   Reply With Quote
Reply

Tags
dropdown list, javascript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:41 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.