aspose file tools*
The moose likes Struts and the fly likes focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "focus " Watch "focus " New topic
Author

focus

p madhavi
Greenhorn

Joined: Jun 10, 2005
Posts: 15
Hi,

On the form, there is a browse button and a submit button. When mouse is pointed on browse button and a "ENTER" button is clicked on keyboard, submit button is activated and hence error(user defined) is displayed since file is not entered. How can i focus on browse button and when mouse pointer is pointing on browse button and "ENTER" button is clicked, then it should open the select file one....

<html:form method="post" action="/Submit.do" enctype="multipart/form-data" >
...
...
<html:file property="File"/ >
...

Any suggestion please??

Thanks.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
you need to use javascript...
you can add the script at the end of the jsp


this requires the hard coding the form bean name you mapped to in your action (if you have only 1 form on that page, you can use form[0]). it also assumes that "fileName" is the property defined for html:file. you can look at the generated HTML to find exactly what you need.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"madhavi",

Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply. Thanks in advance, and we look forward to seeing you around the Ranch.
p madhavi
Greenhorn

Joined: Jun 10, 2005
Posts: 15
Hi,

This is the way i tried:


function putFocus() {
if (document.forms.length > 0) {
document.forms[0].usrFile.focus();
}
}

But what is happening is, the focus is there in the text area of file. I want to focus on Browse button so that when I click the keyboard button "ENTER", browse button should be activated and select file window should pop up. But the button "Process" is activated instead.
what do i need to change in the code??
Any suggestions??

Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Try this:

Use your browser's "view source" utility to find out what function is performed by the browse button.

Then add the following event to the html:file tag:

on key press="if(event.keyCode==13)browseFunction();"

Substitute the name of the function performed by the browse button for "browseFunction()" above.

This will make is so that if the cursor is positioned on the file text control when the user presses enter, it will be as though they had pressed the browse button.


Merrill
Consultant, Sima Solutions
p madhavi
Greenhorn

Joined: Jun 10, 2005
Posts: 15
There is no specific function, basically select file window pops up when browse button is clicked normally. Below is the code:

<html:form method="post" action="/Trans.do" enctype="multipart/form-data">
<b>Select File</b> <html:file property="usrFile"/>
<html:submit value="Process"/>
</html:form>

So there is no code to add for browsefunction.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"madhavi",

While you didn't miss the direct replies to your question, you must have somehow missed my previous request in this thread to change your display name in order to comply with our naming conventions. I'm going to lock this thread until that happens. You can send me an email when you've made the change and I'll go ahead and unlock it. Failure to comply with our policies may result in the termination of your account. Thank you.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
madhavi,

Check your private messages please.
p madhavi
Greenhorn

Joined: Jun 10, 2005
Posts: 15
Any suggestions to my problem....

Since <html:file....> tag creates text and browse buttone, there is no way i can focus separately on browse button....is there any alternative for it??

Thanks.
p madhavi
Greenhorn

Joined: Jun 10, 2005
Posts: 15
Hi,

I tried to write a small script...

<Script Language="Javascript" >

function focus1() {
if(document.all.usrFile.click())
return true ;
else
return false ;
}
</script>

But the problem is when i focus on browse button with mouse and then click "enter" button, the file dialog opens and once the file is selected and submit button is clicked, the data in the text field is gone and no process is performed.....

Any suggestions ??
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: focus