0

The search mechanism below is working perfectly if the search.png is clicked. Getting it to also work when the text cell is active and the Enter key is pressed has not worked.

If the text cell is empty it does complain, focus and stop. But if a string has been entered it fails. The alert displays the correct URL and if I copy and paste from the alert into the browser, it works as it should. It does get submitted by the Enter key, but it appears that it's not submitting the full URL, truncating it after the question mark.

Where is this going wrong?

<form action ="" class="form" onSubmit="srch();" id="dvcsearch">
    <input type="search" placeholder="Search for a device by name" class="biginput" id="dvclist" size="25"/>
    <img class="search-png" src="/images/graphics/search.png" onClick="srch();">
</form>



<script>
function srch() {
  var p = document.getElementById('dvclist').value;
  if (p == "") {alert("Please enter the device you're seeking");
    document.getElementById('dvclist').focus();  
    return false;
    }
  else {   
    document.getElementById('dvcsearch').action = 'cgi-bin/mdvl.cgi?prcdrs~device~srch~'+p; 
    alert(document.getElementById("dvcsearch").action);
    // return true;
    document.getElementById("dvcsearch").submit();
       }
}
</script>
JAC
  • 1,061
  • 1
  • 10
  • 15
  • You need `onsubmit="return srch();"` so that `return false` will stop the submission. – Barmar Jun 20 '22 at 17:13
  • Thanks, but that's not the problem. I can stop the submission just fine and that's among the ways. My problem is getting it to submit properly when the text has been entered and the Enter key is pressed. – JAC Jun 21 '22 at 18:28
  • See https://stackoverflow.com/questions/27807853/html5-how-to-make-a-form-submit-after-pressing-enter-at-any-of-the-text-inputs – Barmar Jun 21 '22 at 18:33

0 Answers0