I have a requirement to restrict input on a textbox. On page load, the text boxes in a repeater are auto-filled with the carton quantity of the item in the repeater. I'm doing this in the OnItemCreated method with this code:
txt.Text = DataBinder.Eval(e.Item.DataItem, "CtnQty").ToString();
What I need to do is restirct the input (preferrably using Javascript) so that if more than the default value is selected, the value is automatically set to the next multiple. If less, whatever value is entered is accepted. So for example, if the default is 12 and 13 is entered, it needs to auto-correct this to 24. If 11 is entered, the value stays at 11.
I have been playing with the Math.round function, like so:
<input type="text" onblur="this.value=Math.round(parseInt(this.value)/12)*12" />
But I can't get it to accept a dynamic value. Doing this causes a 'server tag is not well formed' parse error:
<input type="text" onblur="this.value=Math.round(parseInt(this.value)/<%# DataBinder.Eval(Container.DataItem, "CTNQTY") %>)*<%# DataBinder.Eval(Container.DataItem, "CTNQTY") %>" />
And then I'll have the problem of the accept if less than default, multiplt if more. I think I need a more detailed Javascript function for this, but after much Googling can't find what I'm after. Any ideas will be most welcome.
Thanks