Reputation: 1
i have the below script where i want to pass the text field value to a variable and display in alert window
<form name='searchdata' id="search_form" >
<div class="col-xs-4" id="form_submit_ins">
<label for="usr">Search Instance</label>
<input type="text" class="form-control" id="ins" id"searchval" placeholder="Instance Name"><br/>
<button class="btn btn-danger navbar-btn" onclick="form_submit();" >Search</button>
</div>
<div>
</div>
</form>
</div>
<script type="text/javascript">
function form_submit() {
var item = document.getElementById('searchval').value;
alert(item);
}
Upvotes: 0
Views: 350
Reputation:
Your input
has two id
's, it can only have one id
change:
<input type="text" class="form-control" id="ins" id"searchval" placeholder="Instance Name">
To:
<input type="text" class="form-control" id="searchval" placeholder="Instance Name">
Upvotes: 0
Reputation: 359
There is something wrong with your HTML (does it have two ID fields? Is one missing a "=" sign?
Your code should work if you fix the HTML to:
<input type="text" class="form-control" id="searchval" placeholder="Instance Name">
Upvotes: 0