i want to return in my view a js function. the logic is this: if a user clicks on a button 'book' without choosing an article, book function will look up in database and sees that there is no product chosen in db, then the page shouldnot go further, but it should give a js message on screen saying that "sorry, first choose a product".
my thought is that i want to give this message in my view function after lookup in db. is it possible that i can return javascript function to page?
pseudo:
function book():
products = Produkt.objects.all()
if products == None:
return HttpResponse("<script type='text/javascript'> some function? </script>")
return render_to_response('book.html', {'products':products}, context_instance=RequestContext(request))
is it correct way?
thanks