I am attempting to have a button with a search value for our most common searches. What I was trying to do is user clicks button and inserts the text WITH the quotes "Some Text".
Right now this is what I am using for a single button. How would I make this so I can use one script with multiple buttons?
<button onclick="searchText()" data-product-name="iPhone 12 Pro">iPhone 12 Pro Max</button> <----Current Button
<button onclick="searchText()" data-product-name="Pixel 5">Pixel</button> <---- Added for what Id like
<button onclick="searchText()" data-product-name="LG">LG</button><---- Added for what Id like
<button onclick="searchText()" data-product-name="Samsung S20 Plus">Samsung S20 Plus</button><---- Added for what Id like
<script>
var i = 0;
var txt = '"iPhone 12 Pro Max"';
var speed = 50;
function searchText() {
if (i < txt.length) {
document.getElementById("search-query").value += txt.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
</script>
I tried adding the following but did not work.
var txt = element.getAttribute('data-product-name');