Reputation: 167
To understand exactly what I'm talking about check out this link
So, I want to get rid of the input box, I mean to type something on a div with a red background for example and when I type google and press enter I want to send me to the google website and when I type yahoo to send me on the yahoo website. How I can achieve this? I'm not very good at javascript. Thanks!
Upvotes: 0
Views: 392
Reputation: 4860
this may help.
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('div[contenteditable]').focus();
$('div[contenteditable]').keypress(function (e) {
if(e.which == 13)
{
switch ($(this).html()) {
case 'google':
document.location = 'http://google.com'
break;
case 'yahoo':
document.location = 'http://yahoo.com'
break;
}
}
});
});
</script>
<style>
div[contenteditable] { background:red; width:200px;height:20px; padding:5px; }
</style>
</head>
<body>
<div contenteditable></div>
</body>
</html>
Upvotes: 2
Reputation: 6700
You can also hide your input by css so it looks like you're writing in a div but really its just an approprietly styled input.
Your version with a little change
Upvotes: 0
Reputation: 9929
You can add a div to your page that has the CONTENTEDITABLE="true" attribute on it. Than add a button or whatsoever that indicated that the user is done (can also be an hit on the return key). At that point, check the value in the div, show an error message if needed or redirect the page if the entered value is valid (e.g. document.location.href = 'http://www.' + userValue + '.com';)
Upvotes: 0