I have a dynamic search button that works very well.
Users type text and database of books and search results are shown.
I also have a search for “new arrivals” where the user has to type “qqq”. This also works without any problems.
To be more intuitive I would like to replace the “qqq” with a submit button link that pretends the user input was “qqq”.
I have tried numerous JavaScript calls but none will even open the PHP search routine file. Hopefully, once the PHP file is open and active I should be able to use MySql to search and display the “new arrivals”.
AJAX Call:
// ESSENTIAL: URL AND NOT PATH
xmlhttp.open("GET","incs/_dbResults-QQQ.php?q="+str,true);
Form Input to activate AJAX search Routine
<label> Book Search: </label>
<input
id = "bufferedInput"
class = "fsn"
type = "text"
size = "42"
name = "search"
value = ""
<?php $onKeyUp = 'onkeyup = "showResult(this.value)"'; ?>
/>
<input
class ="bgy p42 rad"
type ="submit"
name ="search"
value ="New arrivals"
onsubmit="showResult(this.value)"
/>
Well, if your script is expecting “qqq”, and you send it “New arrivals”…
Surely you can just…
?
Oh, but it’s a SUBMIT button. You SURE thats what you want it to do? Your form field is triggering onkeyup. If you’re SUBMITTING the form, your script will run, and then the form will submit… what’s the action on the form?
I want to replace the user’s qqq input with the New Arrivals submit button:
I forgot to show the hidden AJAX/JavaScript:
<div class="w88 mga">
<form action="?" method="get">
<div>
<br>
<label>Book Search: </label>
<input
id = "bufferedInput"
class = "fsn"
type = "text"
size = "24"
name = "search"
value = ""
<?php
# ONLY USE andres
# IF AND ONLY IF ISSET($_GET['andres'])
$onKeyUp = 'onkeyup = "showResult(this.value)"';
# $andres = $_GET['andres'] ?? $onKeyUp;
?>
/>
<input
class ="bgy p42 rad"
type ="submit"
name ="search"
value ="New arrivals"
<?php $onKeyUp = 'onkeyup = "showResult(' ."qqq" .')"';?>
/>
</div>
</form>
</div>
<input
class ="bgy p42 rad"
type ="submit"
name ="search"
value ="New arrivals"
<?php $onKeyUp = 'onkeyup = "showResult(' ."qqq" .')"';?>
/>
</div>
Start Script Evaluation.
PHP processes. Sets $onKeyUp to the value given. Does nothing with it.
Resulting HTML:
<input
class ="bgy p42 rad"
type ="submit"
name ="search"
value ="New arrivals"
/>
</div>
Hands HTML to browser.
Browser says "There’s a form. And a submit button. When someone pushes submit button, stringify inputs for URL addition, and run form.
… Javascript looks at it, says “Okay, it’s a button. Nothing for me to do.”