Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catching the onKeyDown value?

Status
Not open for further replies.

golyg

Programmer
Jul 22, 2002
319
US
I have a client side script that under certain situations would call a server side function.
The problem that i am having is that the function is an onclick event. The button that fires this onclick event is a design time control.

I keep getting this error:
Type mismatch: 'login_onclick'

here is my function:
Code:
sub buttonPress()
dim i 
 i = window.event.keyCode
 if i = 13 then
	btnLogin_onclick()
	'msgbox "hello"
 end if 
End sub

any ideas?

thanks
 
Hello golyg,

In your case, just call the onclick processor.
Code:
if i = 13 then
    call btnLogin_onclick()
    'msgbox "hello"
    'exit sub
end if
regards - tsuji
 
I keep getting a 'type mismatch error: btnLogin_onclick'
error.
The btnLogin_onclick() is a sub, does that matter?

thanks
 
actually, the btnLogin_onclick() sub has the
tag
<code>
<script ID=&quot;serverEventHandlersVBS&quot; LANGUAGE=&quot;vbscript&quot; RUNAT=&quot;Server&quot;>
</code>

and my button_press has this tag:
<code>
<script LANGUAGE=&quot;vbscript&quot; runat&quot;Client&quot;>
</code>

just wanted to give as much details as possible.

thanks,
 
golyg,

If it is a sub, use
Code:
if i = 13 then
    btnLogin_onclick
    'msgbox &quot;hello&quot;
    'exit sub
end if
It should do as good as btnlogin button being click. If the latter is not functioning, neither should the former.

regards - tsuji
 
Nope,
still getting the type mismatch error....

Tsuji, thanks for all your help on this!


 
Hello golyg,

We are not giving up, myself and other members-ready-to-help on this unless you are.

[1] What is runat=&quot;client&quot; ? unless there is something special.
[2] I may be simple-minded. I believe in reduction to clear cut principle. You might be working on very long scripts but the thing should work based on the working building block. Unessential detail should not be dealt with on the road. You say it is not working that means something else which should not be due to idea reflecting in the simple code. I just use again something we are involving in recent postings.
Code:
<html>
<head>
<script language=vbscript>
sub proc_keycode
	if window.event.keyCode=13 then
		button_onclick
		exit sub
	end if
'or to the same effect more physically simulating a click
'	if window.event.keyCode=13 then
'		document.getElementByID(&quot;buttonID&quot;).click
'		exit sub
'	end if
end sub
sub button_onclick
	msgbox &quot;button is clicked&quot;
	'do something
end sub
</script>
</head>
<body>
<form>
<input type=&quot;text&quot; name=&quot;mytext&quot; onkeydown=&quot;proc_keycode&quot;><br><br>
<input type=&quot;button&quot; id=&quot;buttonID&quot; name=&quot;mybutton&quot; value=&quot;here you go&quot;  onclick=&quot;button_onclick&quot;>
</form>
</body>
</html>
Both blocks (one commented out) should be enough to simulate a click on the button. Can you verify it on your box? Server side code should not interfere this elementary functionality. That is why I say if physically click the button works, the sub/function call should work as well. (Only details are that if your handler use something on the style or position etc of the mouse, then it is different.)

regards - tsuji
 
thanks for not giving up and sticking with me on this...

here is what i have,

<tr><td> Password: </td>
<td><INPUT type=&quot;password&quot; id=txtPswd name=txtPswd size=&quot;12&quot; onkeydown=&quot;buttonPress()&quot;></td>
</tr>

<script>
...
...
<some other code>
...
...
</script>
<script LANGUAGE=&quot;vbscript&quot;>

sub buttonPress()
dim i
i = window.event.keyCode
if i = 13 then
btnLogin_onclick
end if
End sub
</script>

The onclick event of the button works fine, just when I hit enter and the focus is on the textbox is where I have problems..
 
golyg,

[1] I don't see any problem with the type password. It operates the same.
[2] Try take the paraentheses away from buttonPress both at
Code:
    <... onkeydown=&quot;buttonPress&quot;>
and
Code:
    Sub buttonPress
[3] The focus problem now raised seems to be a moving target. You didn't mention it and now seem to suggest it is the problem and not the click. I don't get it. By you can always set the focus first then simulate a click, like:
Code:
sub buttonPress   'I have taken away () already here
dim i 
  i = window.event.keyCode
  if i = 13 then
     document.getElementByID(&quot;btnLoginID&quot;).focus
     btnLogin_onclick
  end if 
End sub
Suppose here you set the btnLogin'id being btnLoginID or similarly focus to wherever you like before a click. In case you have a hierachy of event, make sure you want the event bubbling up.
[4] Lastly should I say if it is really a problem other than the originally raised, you should open a new thread and state the real problem at hand.

regards - tsuji

 
Thanks tsuji,
I'm posting a new thread with my new symptoms...

thanks again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top