I'm trying to build a searchable database that will allow a user to type in the name of a state and see a small subset of that state's laws (traffic laws, age of consent, conceal and carry laws, etc.). I'm getting confused on how a user submitted string will interact with my Javascript objects. I have seen people submitting questions regarding adding user-submitted integers or concatenating but what I am trying to do is slightly different.
I am able to assign the user-submitted text as a variable via the getElementById method but now I'm lost. My question is this: How do I connect that user submitted variable with my objects' key values in Javascript so that when a user types in "Minnesota" and clicks the find button it retrieves and displays my Javascript data (which is information about Minnesota's state laws stored as object keys)?
Here is a subset of the HTML in question:
<div class="formDiv">
<form id="searchbox" action="">
<!--Search field-->
<input id="search" type="text" placeholder="Ex: Minnesota"></input>
<!--Submit button-->
<input id="submit" type="submit" value="Search"></input>
</form>
</div>
<!--Where I want the Javascript object to be displayed-->
<div class="answer"><p></p></div>
And here is the Javascript with just one object for simplicity:
var Minnesota = {
name: "Minnesota",
consent: 18,
openBottle: true,
deathPen: false,
conceal: "Conceal & Carry",
txtDriveBan: true,
talkDriveBan: false
}
$(document).ready(function() {
$("#submit").on('click', function(){
var State = document.getElementById("#search");
//At this point, what do I write to display Minnesota's information stored in the object?//
});
});
Thanks very much for any help!