I wanted to get the selected text from the dropdown, But I am getting value if I use request.GET['Type']
. I wanted to
get Data001
instead of Value001
def index(request):
print("The output: ",request.POST.get('Type'))
return render(request,'index.html',content)
<div class="form-row last">
<div class="form-wrapper">
<label for="">Meeting Type</label>
<select id="Type" name="Type" class='form-control'>
<option disabled="disabled" selected="selected">Choose option</option>
<option value='Value001'>Data001</option>
</select>
</div>
</div>
<div class="form-wrapper">
<button data-text="Book" type="submit" name="action" value="book">
<span>Book</span>
</button>
</div>
Please note that, There are 30+ dropdown options and I must use values in the dropdown. Kindly help me to get the selected option instead on value
2
Answers
So if this is using for filter purposes and you cannot change the values inside of
option
tags.Then you can use
AJAX
, you can get the .innerHTML of the selected option, and pass that as adict
to yourviews.py
functionadd a new input tag with hidden type.
add onchange listener on select of id "Type"
in callback function of event listener, replace the input tag value with the inner text of changed value in select
by this way, you can use it without ajax a