简体   繁体   中英

How to Input type text as submit button in html?

I have a form without input type submit .

<form class="form" action="" method="post" name="new-service"
 enctype=multipart/form-data>  
  <span class="pull-right">
    <input id="sa" name="Searchs" type="text" placeholder="Analyze Search"
     class="form-control input-xlarge search-query center-display"
     required="">    
    <span class="pull-right"> <a class="btn btn-success"  href="#"
     onclick="
       this.href='/recrawl?search=' + document.getElementById('sa').value;
       somefunction(this, event);
       return true;
    ">  Analyze Data </a>
    <br><br>
  </span>
</form>

above form work when click on Analyze Data .

but now I want It run on press Enter of Input type text tag

I tried

<input id="sa" name="Searchs" type="text" placeholder="Analyze Search"
 class="form-control input-xlarge search-query center-display" required=""
 onclick="
   this.href = '/recrawl?search=' + document.getElementById('sa').value;
   somefunction(this, event);
   return true;
"> 

but it is not working ?

<input id="sa" name="Searchs" type="text" placeholder="Analyze Search" class="form-control input-xlarge search-query center-display" required="" onKeyPress="postURL(event, this)">

function postURL(e, textarea){
   var code = (e.keyCode ? e.keyCode : e.which);
   if(code == 13) { //Enter keycode
      window.location.href ='/recrawlsearch='+document.getElementById('sa').value;
   }
}

Hope this window.location.href would help you.

The input element don't have the href attribute, so, this.href = xxxx is not working.

If you want to click input element, use window.location.href = xxx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM