|
|
#1 |
|
New Member
![]() Join Date: Feb 2010
Posts: 10
|
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. |
|
|
|
|
|
#2 |
|
Super Moderator
![]() Join Date: Oct 2008
Location: Arizona, USA
Posts: 1,053
|
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 */
__________________
John Darling Graphic / Web Designer SmarterTools Inc. (877) 357-6278 www.smartertools.com |
|
|
|
|
|
#3 |
|
Bronze Member
![]() Join Date: Mar 2010
Location: Norfolk, UK
Posts: 78
|
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.
|
|
|
|
![]() |
| Tags |
| dropdown list, javascript |
| Thread Tools | |
| Display Modes | |
|
|