|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
General - Question - Key Down on TextBox
this is using Classic ASP
how can i put an onkeydown event on the textbox wherein the action would be the same as clicking the button next to it. any help is highly appreciated. thanks. |
|
#2
|
||||
|
||||
|
You cant do it in asp as it is a client side function, you will need to use javascript"
Code:
onkeypress="document.form_name.submit();"
__________________
For my first trick watch me turn a zero into a one... |
|
#3
|
|||
|
|||
|
thanks but it still doesnt work. do i need to put additional code?
Quote:
|
|
#4
|
||||
|
||||
|
Hi,
What do you mean by "not working" ? Please explain more. Dr_Rock just give you an example as you provide no information of your code. Try this example, whenever you type something (include backspace), "Testing" would be pop-up. Code:
<html>
<script type="text/javascript">
function ClickbtnTest(){
alert('Testing');
}
</script>
<form name="Page">
Input Text:
<input type="text" onkeydown=ClickbtnTest() />
<input type="button" name="btnTest" value="Test" onClick=ClickbtnTest()>
</form>
</html>
Hope it helps |
|
#5
|
|||
|
|||
|
thanks. the testing you posted worked.
but when i modified it to this: Code:
<script type="text/javascript">
function ClickbtnTest(){
document.form1.submit();
}
</script>
Code:
<form name="form1" method="post" action="index.asp"> <input name="medName" type="text" id="medName" size="50" width="350"onkeydown=ClickbtnTest() > <input name="Display" type="submit" id="Display" value="Submit" onClick=ClickbtnTest()> </form> it doesnt return anything.. thanks for the time. Quote:
|
|
#6
|
||||
|
||||
|
Hi,
Your code looks fine. Again what does "it doesnt return anything" mean ?? Page not submitted? Or go to blank page? Or something else? Do you get what you want when simply click the button? Add testing line to see whether enter the javascript function or not Code:
<script type="text/javascript">
function ClickbtnTest(){
alert('Submit');
document.form1.submit();
}
</script>
|
|
#7
|
|||
|
|||
|
thank you very much for the time.
the testing line works. the message box showed up. but the behavior is not the same as clicking the button. and while on that topic, i noticed that after typing a character, the onkeydown was automatically triggered. do you know a way where that event should only be called after pressing the enter key. thanks. Quote:
|
|
#8
|
||||
|
||||
|
Hi,
Add function to check whether Enter is pressed Code:
<script type="text/javascript">
function CheckEnterKey(e) {
if(window.event) {
// IE
keynum = e.keyCode;
} else if(e.which) {
// Netscape/Firefox/Opera
keynum = e.which;
}
if (keynum == 13) {
// 13: Enter
return true;
} else {
return false;
}
}
function ClickbtnTest(event){
if (CheckEnterKey(event)) {
document.form1.submit();
}
}
</script>
<!-- CODE -->
<form name="form1" method="post" action="index.asp">
<input name="medName" type="text" id="medName" size="50" width="350" onkeypress=ClickbtnTest(event)>
<input name="Display" type="submit" id="Display" value="Submit" onClick=ClickbtnTest(event)>
</form>
P.S. maybe you should ask moderator to move this thread to "HTML, JavaScript And CSS Help". |
|
#9
|
|||
|
|||
|
thanks a lot. i tried it but when i pressed enter, it still didnt do the actions that the clicking of the button does.
And sorry if i posted this on the wrong thread. |
|
#10
|
||||
|
||||
|
Do you mean the FORM was not submitted?
__________________
selwonk |
|
#11
|
|||
|
|||
|
Quote:
i think the form was submitted, but the procedures that the button does when it was clicked wasn't called. thanks. |
|
#12
|
|||
|
|||
|
thanks a lot for those who heloed. it's working fine now.
![]() |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > General - Question - Key Down on TextBox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|