|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
Adapting existing js drop-down menu.
Hi! I have an js menu which enables users to select the area in which they live, from one menu, by first selecting their County from another.
This works really well, but now I want to adapt it. I want it to alway show a selection of areas of one particular County that is always selected by messing with the form. here is the original code Code:
var londonareasArray = new Array("('Select borough/district','',true,true)",
"('Barking & Dagenham')",
"('Barnet')",
...etc etc
"('Last area')");
var nextcountyArray.......
Code:
function populateBorough(inForm,selected) {
var selectedArray = eval(selected + "Array");
while (selectedArray.length < inForm.borough.options.length) {
inForm.borough.options[(inForm.borough.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.borough.options[i]=" + "new Option" + selectedArray[i]);
}
if (inForm.county.options[0].value == '') {
inForm.county.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
Code:
<form name="form1"> <select name="county" onChange="populateBorough(document.form1,document.form1.coun ty.options[document.form1.county.selectedIndex].value)"> <option selected value=''>Where are you looking?</option> <option value="londonarea">All LONDON Areas</option> <option value="bedfordshire">Bedfordshire</option> <option value=....etc etc </select> <select name="borough"> <option value=''></option> </select> </form> Now I have been messing around with the form so instead of 'onChange' it is 'onFocus' and commented out all option values except one of them say "londonarea" but you have to select it to get the area options for londonareas. I looking for a way to get it to come up with the londonarea options when the page loads. I have tried this sort of approach where I give londonarea as the value Code:
<select name="county" onFocus="populateBorough(document.form1,document.form1.coun ty.options[document.form1.county.selectedIndex].value == "londonarea")"> But it does not seem to work. Could someone please give me the correct approach? PS I know what you might be thinking, "why does he want js in the first place?" well, after this is solved, I'll php to select the County option carried over as a variable from previous page! |
|
#2
|
||||
|
||||
|
hey again sry i didnt get your emails till now, i think i know what u ment now.
try: function _populate() { window.document.form1.county.selectedIndex=1; populateBorough(document.form1,document.form1.coun ty.options[document.form1.county.selectedIndex].value); } <body onload="_populate()"> that should do it. colton22 |
|
#3
|
||||
|
||||
|
(ps: keep the ONCHANGE!)
colton22 |
|
#4
|
||||
|
||||
|
Thanks Colton22
I have reading about calling the index of the form before and not quite understanding it, but now I know: it starts from 0, 1, 2 etc right? Now I can steam ahead and play about with it using php! Cheers |
|
#5
|
||||
|
||||
|
yea, in a select...
--_____________________ -/---------SELECTED--------\ |----------OPTION1----------| - Index of: 0 |----------OPTION2----------| - Index of: 1 |----------OPTION3----------| - Index of: 2 |----------OPTION4----------| - Index of: 3 |----------OPTION5----------| - Index of: 4 |----------OPTION6----------| - Index of: 5 |----------OPTION7----------| - Index of: 6 ``````````````````````` hope this helps colton22 ps like my drawing?? lolol |
|
#6
|
||||
|
||||
|
are you there?
|
|
#7
|
||||
|
||||
|
yeah, hows it goin'?
|
|
#8
|
||||
|
||||
|
pretty good, lol, so i guess that worked ah?
|
|
#9
|
||||
|
||||
|
No need to guess, have a look on parentpages.co.uk ...the homepage has been done again and your js code has been used to copy the selections to the new window, where one can make new selections/searches. It's content is pretty boring stuff for you, sorry, but it works the way I had originally wanted. So thanks very much again.
BTW how is your's getting on, downloading music from the menu I seem to remember..maybe downloading DOS script files! |
|
#10
|
||||
|
||||
|
lol, im glad your website is up and running the way you wanted it now, if you have any more questions ask alright?
anyway i havnt really worked on my website much lately, i do have a question about that though, and its "How would i get <objects> to work in all, IE, NN, FF, OPERA, EXC??" thats it, but after that, ill start working on what is left of my website and then, there we are, send me a logo of you website, ill see if i can put a link from my website to yours, email it, g2g c ya l8r colton22 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Adapting existing js drop-down menu. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|