Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have one input textbox and button on my page. actually what i want is --- on click of the button if textbox is not empty then redirect to url which is in textbox... nd it should also be redirected when we press enter key in the textbox.. i need javascript function for that... i tried many things.. i am totally new...

What I have tried:

function doKey(e) {



       if (event.keyCode == 13) {

           var x = document.getElementById('<%=editbox_search.ClientID%>');

           var val = x.value;
           if (val == "") {
               return false;
           }
           else {


               window.location = <%= Page.ResolveUrl("~/")%>+'Search/'+val;


           }
           return false;
       }



   }
Posted
Updated 30-Mar-18 22:34pm

1 solution

Try this:
HTML
<!DOCTYPE html>
<html>
<script language="javascript" type="text/javascript">
    function buttonClick(){
    var url = document.getElementById("inputURL").value;
    window.location = url;
    }
</script>
<body>
URL: <input type="text" id="inputURL" name="inputURL" value=""><br>
<input type="button" value="click" OnClick="buttonClick()"/>
</form>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900