javascript - Drop down menu with image switch -
i trying image switch out depending on person picks in drop downwards menu. html , js in 2 different files.
this part of html:
<select id="breed_0_field" name="breed76" onchange="javascript: wizard();" onkeyup="javascript: wizard();" tabindex="4"> <option selected="selected" value="select one">select one</option> <option value="other/mix">other/mix</option> <option value="0">--- mutual breeds----</option> <option value="border collie">border collie</option> <option value="boxer">boxer</option> <option value="corgi">corgi</option> <option value="dachshund">dachshund</option>
for js part:
breed = document.getelementbyid("breed_0_field").value; selectdog() function selectdog() { dog_type=0 switch (breed) { case "affenpinscher": // affenpinscher // affenpinscher document.getelementbyid("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/dog_larger/blank.gif"; break; case "affenpinscher": // affenpinscher // affenpinscher document.getelementbyid("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/dog_larger/affenpinscher.gif"; break; case "afghan hound": // afghan hound // afghan hound document.getelementbyid("dog_breed_picture").src = "http://handicappedpet.net/helppets/images/avatars/gallery/dog_larger/afghan_hound.gif"; break;
the problem is, utilize work numbers. value in html part utilize 1,2,3,4...and right image matched case 1,2,3,4...but need value html it's name otherwise later on downwards code shows number instead of breed name.
how made image switch kinda work string instead of numbers?
my bad! apparently work!
my problem had function if (breed > 0){selectdog()} never work because i'm no long using numbers.
but can indeed utilize strings case.
javascript html
No comments:
Post a Comment