开发者

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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜