'JavaScript radio button into dropdown with validation
I'm looking to change this code into a dropdown menu, changing the list is fine but cant figure out the onclick
event.
for (var z = 0; z < ShipTable.length; z++)
sOutput += "< input type=radio name=\"ZONE\" value=\"" + z
+ "\"" + (z == ZoneChecked ? " checked" : "")
+ " onClick=\"NewZone(this.value)\">" + ShipTable[z].zone + ";
I've changed the above into:
sOutput += "<select class=\"nopselect\" onClick=\"NewZone()\"><option>Select Delivery< /option>";
for (var z = 0; z < ShipTable.length; z++)
sOutput += "< option name=\"ZONE\" value=\"" + z
+ "\" >" + ShipTable[z].zone + "</option>";
sOutput += " < /select>< /TD > < /TR>";
but this function want this function to work with the drop down:
function NewZone(value) {
SetCookie("ZoneSelected", value, null, "/");
var RegionCookie = iGetCookie("RegionSelected");
if (RegionCookie != null && RegionFromZone.length && !Element(RegionCookie, RegionFromZone[ZoneParam])) DeleteCookie("RegionSelected", "/");
location.href = location.href;
}
Solution 1:[1]
You may want to use the onChange
event instead of onClick.
sOutput += "<select class=\"nopselect\" onChange=\"NewZone()\"><option>Select Delivery< /option>";
onChange is triggered when you change your selection in the dropdown, instead of when you simply click somewhere on it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Frode |