This was a subject closed up by no means answered on this:
That is the code:
```
<script kind="textual content/javascript">
operate showfield(identify)
if(identify=='Different')doc.getElementById('div1').innerHTML = 'Different: <enter kind="textual content" identify="different" />';
else
doc.getElementById('div1').innerHTML='';
</script>
<choose identify="select_opt" id="select_opt" class="form-control" onchange="showfield(this.choices[this.selectedIndex].worth)" required>
<choice worth="">Please Choose Supply</choice>
<choice worth="Search Engine">Search Engine</choice>
<choice worth="Social Media">Social Media</choice>
<choice worth="E-Mail Campaigns">E-Mail Campaigns</choice>
<choice worth="Exhibitions">Exhibitions</choice>
<choice worth="Different">Different Sources, Please Specify</choice>
</choose>
<div id="div1"></div>
This works positive in that it’ll show a textual content enter field to kind in.
The query I’ve is how does the inputted textual content turn out to be a worth you could enter into the database?
The choose fields and some other info that’s to be added to the database must be wrapped in a form field, in order that the shape’s info will be despatched to some backend code that updates the database.
I understand how to wrap in a kind discipline. Try this on a regular basis and I exploit dropdowns steadily. The worth of that is suppose to be what’s typed within the enter field. However as written, it simply provides the phrase “Different” to the database as a result of that’s the worth.
So, based mostly on that JS, I wasn’t certain how one can take the textual content typed and use that as the worth that goes to the database.
<choice worth="Different">Different Sources, Please Specify</choice>
Give the choice within the HTML code a reputation attribute, and that can be submitted to the database.
Must you add and take away the identify attribute from the choice relying on if that choice is legitimate or not? No you shouldn’t. The choice ought to all the time be submitted to the backend kind, and that sort of resolution must be made by the backend itself.
Why ought to the backend be chargeable for that sort of resolution? As a result of you shouldn’t belief something from the frontend. It’s too simply exploited by every kind of issues. The backend is the place the place dependable choices are made.