Instead of writing a script, in your data source taskpane >> double click on the field >> check the cannot be blank checkbox. When you try to submit or save the InfoPath form, it will require that your quantity be set. No script required :-) A red star will be displayed in the quantity field until the user enters a value.
Jason
http://www.k2distillery.com/