jeudi 26 mars 2015

How to implement AUTO submit form for searching via JavaScript?

I have created form which automatically search text (this text is recognized from recorded voice). After recording user's voice JS (below) recognize voice as text, then call form by id="searchform". This form then call function, which search word in database of words. JS code:



final_transcript = capitalize(final_transcript);
var queryTextField = document.getElementById("search_query");
queryTextField.value = final_transcript;
//automatic submit button search form is if form
document.getElementById('searchform').submit();


JS code call function "media/search" which is implemented in this HTML form:





<li><form class="input-group navbar-form" id="searchform" action="<?php echo base_url();?>media/search" method="post"></li>
<input type="text" class="form-control" placeholder="Vyhladat titulky..." id="search_query" name="string" />
<button type="submit" name="btn_search"></button>
</form>



"Media/search" function, which search recognized text:





//Search function
function search($string = null) {
//function can search string sent in url or in form
$data['string'] = isset($_POST['string']) ? $_POST['string'] : $string;
//For not null form
if(! empty($data['string'])) {
//Searching in database
$gid = (! access(3) && ! access(4)) ? $this->userinfo('group') : null;
$data['list'] = $this->media_model->search($data['string'], $gid);
}
//Data are set to show
$this->template->view("media/search", $data);
}



Auto submit seems works because the page with results is shown after record of voice, but no results of searching are shown. I think that searching function works, but with no value, so it seems that it search "no word". I need help, I am new in JS. This code was created in my school and I need to change it to work automatically


Aucun commentaire:

Enregistrer un commentaire