Home > Mobile >  Enter button gets trigrred while enter new line in input form
Enter button gets trigrred while enter new line in input form

Time:01-21

im working on a project where a user can describe his location in multiple lines but when i press enter button for new line in input form it gets submitted into database. i feel myself stucked here. help me to get rid of this please

my html code is:

<form method="POST" id="name-form">
  <div >Describe Location</div>
  <input type="text" value='Describe Location' name="disc" >
  <input type="submit" value="discribe" name="discribe" >
</form>

and my php code is :

if (isset($_POST['discribe'])) {
    $disc =  htmlspecialchars(trim($_POST['disc']));
    $qry =  "UPDATE `Location` SET disc=:disc WHERE city = :city";
    $result = $conn->prepare($qry);
    $result->bindParam(':disc', $disc, PDO::PARAM_STR);
    $result->bindParam(':city', $city, PDO::PARAM_STR);
    $result->execute();
}

please help me

CodePudding user response:

if you go with input type text and do not want any textarea then just used this jquery code

$('form [name="disc"]').keydown(function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        return false;
    }
});

CodePudding user response:

Instead of using "<input type="text" ...>" you can use "<textarea ..>" markup. It can be easily used in forms and shouldn't submit on enter while in this text area.

  •  Tags:  
  • Related