• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

focus

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
p madhavi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
madhavi,

Check your private messages please.
 
p madhavi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic