I’ve created a drop down menu which contains 5 choices. When a user selects a choice and presses the submit button, how do I transfer that “selection” to the backend/server in Django?
After that, when the value of the selection reaches the backend, I intend to use the value to create another form. There are 5 forms to choose from (one for each choice) and the type of form that appears will depend on the value of the original selection.
This is what I have so far, but I get the error, “Key ‘selection’ not found in QueryDict: {}”
Here’s the HTML file:
<div id = "f1" style="display:none">
<form name= "form1" action='/products/{{ action }}/' method='get'>
<p class="choice-header"> Product: </p>
<select id = "g1" title="selection" onchange = "showForm()">
<option value = "0">--</option>
<option value = "1">Form 1</option>
<option value = "2">Form 2</option>
<option value = "3">Form 3</option>
<option value = "4">Form 4</option>
<option value = "5">Form 5</option>
</select>
<div id= "b1" style="display:none">
<input class="button" type=submit value="{{ button }}">
</div>
</form>
</div>
Here’s the Django views.py file
def new2(request):
form_no = request.GET["selection"]
if form_no == 1:
form_to = Form1()
c = RequestContext(request, {
'action': 'add/2',
'button': 'Add',
'form': form_to,
})
return render_to_response('links/add.html', c)
Thanks for the help!
This isn’t really a Django issue. You just haven’t given your
selectelement anameattribute.