i want implement country-selection-input. in other words, i've got form 25x25px flag, want clickable - say, german default, first click changes netherlands, second swiss or w/e.
the last chosen value needs in post-array other values of form.
i've tried accomplish using 3-way checkboxes javascript, i'm going need more 3 options.
any idea on how this? i've thought input select, hiding current value - don't know how submit change next value.
thanks in advance input, , please don't judge me such question - first js/html/css project. :-)
you can this:
html
<form method="post"> <img src="german.png" onclick="switchcountry(this);"/> <input id="country" name="country" type="hidden" value="german" /> <input type="submit" value="submit" /> </form> javascript
var countries = ['german', 'netherlands', 'swiss']; var switchcountry = function(img) { var input = document.getelementbyid('country'), oldvalue = input.getattribute('value'), newvalue = countries[(countries.indexof(oldvalue) + 1) % countries.length]; // switch input value posted form input.setattribute('value', newvalue); // switch graphical representation of country img.setattribute('src', newvalue + '.png'); }; example here http://jsbin.com/alasip/1/edit
Comments
Post a Comment