In your case, the browser opens the Excel document, where it reloads the page with excel documents and there is no possibility of executing the JavaScript code!
Did you tried the jQuery code provided by other user?
Sorry Mate, its bit difficult for you to achieve this using classic Javascript, u better start learning JQuery and I bet u can start using it in an hour or 2.
I reckon that u r almost there, u just need a reference to be added to JQuery, which u could download from the below link for free
johnss
Member
36 Points
26 Posts
Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 12:48 PM|LINK
Hi friends,
I have a below JavaScript code which will open an excel sheet.
<script language="JavaScript">
var myApp = new ActiveXObject("Excel.Application");
if (myApp != null)
{
myApp.visible = true;
myApp.workbooks.open("C:\Spreadsheet.xls");
}
<script>
After opening a Excel sheet. I need a Javascript code which need to Press letter Y(ascii code = 89) defaultly through Javascript Code not by keyboard.
Can anyone tell me that Javascript code?
Ramesh T
Contributor
5171 Points
833 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 12:56 PM|LINK
Hello Mate,
If u r okay to use JQuery 1.3 or greater, then this will help you
var e = jQuery.Event("keydown"); e.which = 89; // Ur key code $("input").trigger(e);roopeshreddy
All-Star
20271 Points
3346 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 01:05 PM|LINK
Hi,
In your case, the browser opens the Excel document, where it reloads the page with excel documents and there is no possibility of executing the JavaScript code!
Did you tried the jQuery code provided by other user?
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
johnss
Member
36 Points
26 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 01:17 PM|LINK
Hi,
Sorry. I am not aware of Jquery. How to concate ur code with below Java Script. Whether my below code is correct? Please correct me if I am wrong
<script language="JavaScript">
var myApp = new ActiveXObject("Excel.Application");
if (myApp != null)
{
myApp.visible = true;
myApp.workbooks.open("C:\Spreadsheet.xls");
var e = jQuery.Event("keydown");
e.which = 89; // Ur key code
$("input").trigger(e); .
}
<script>
Ramesh T
Contributor
5171 Points
833 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 01:35 PM|LINK
Sorry Mate, its bit difficult for you to achieve this using classic Javascript, u better start learning JQuery and I bet u can start using it in an hour or 2.
I reckon that u r almost there, u just need a reference to be added to JQuery, which u could download from the below link for free
http://docs.jquery.com/Downloading_jQuery
Also, below is the link to JQuery tutorial
http://docs.jquery.com/Tutorials
Cheers.
Please mark this as answer if helps.
johnss
Member
36 Points
26 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 03:05 PM|LINK
Hi,
I downloaded the JQuery. When I opened, it says 'Window' is undefined" Error. Is it possible to acheive my request through Java Script?
Thanks
roopeshreddy
All-Star
20271 Points
3346 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 03:21 PM|LINK
Hi,
After downloading the jQuery did you insert into your asp page?
<script type="text/javascript" src="<path of the jQuery file>">
</script>
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
johnss
Member
36 Points
26 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 03:57 PM|LINK
When I downloaded there is a file "jquery-1.7.1" Where I have to put the below code
var e = jQuery.Event("keydown");
e.which = 89; // Ur key code
$("input").trigger(e); .
Sorrry for asking some basic questions. Since I am new to Jquery
Ramesh T
Contributor
5171 Points
833 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 04:08 PM|LINK
No worries.
Just add the file u downloaded to ur project and add reference to it in your page as Roopesh advised.
Cheers.
johnss
Member
36 Points
26 Posts
Re: Need Javascript Code to Press Letter "Y" defaultly not by Keyboard
Feb 13, 2012 04:21 PM|LINK
I have done below.. Please correct me to add Jquery code
<script type="text/javascript" src="C:\jquery-1.7.">
var myApp = new ActiveXObject("Excel.Application");
if (myApp != null)
{
myApp.visible = true;
myApp.workbooks.open("C:\Spreadsheet.xls");
}
</script>
Where to add the below Query?
var e = jQuery.Event("keydown");
e.which = 89; // Ur key code
$("input").trigger(e); .