Alternative for File Button

Hi all,

I have a situation in which i need to use a TextBox and a Button in jsp/Html and the desired functionality is like this , "If i click the button , File Browse window should open and once if i choose a file and click open then the selected file location should be placed as the TextBox value".

For this I can Use a File Buuton but situation is like "the Browse button is not near the assosiated TextBox as in the case of File Button".

Any Solution is greatly appriciated.

Regards

Siva Kumar Reddy P

[549 byte] By [sivakumarreddypa] at [2007-10-2 16:16:17]
# 1
I don抰 think you can抰 use JavaScript to automatically populate an input field of type file. If you could, you could easily create a page the automatically downloads files from peoples computers, it would be a serious security threat.The user has to click the file button.-S
slenzia at 2007-7-13 17:06:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hey dude, Its very simple...

Try this out

<html>

<head>

<title>Browse Demo</title>

<body>

<input type="file" name="tp">

</body>

</html>

.

Anything else ?

YogendraJ123a at 2007-7-13 17:06:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You must have missed the part where he didn't want the button to be next to the textfield...
linxpdaa at 2007-7-13 17:06:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

[nobr]Well you can't get around requiring the input type="file" being on the page.

But that doesn't mean you have to show it to everyone...

Basically if you can have an independant button that triggers the popup from an onclick event you're set.

This works in IE.

Unfortunately it doesn't appear to in Firefox

<html>

<head>

<script language="javascript">

<!--

function promptForFile(theForm){

// popup the dialog prompt for a file

theForm.f1.click();

// copy the value into a text field

theForm.t1.value = theForm.f1.value ;

}

//-->

</script>

</head>

<body>

<form method="post" enctype="multipart/form-data">

<input type="file" name="f1" value="hello" style="display:none">

<input type="text" name="t1" size="50" style="text-align:right"><br>

<input type="button" name="b1" onclick="promptForFile(this.form)" value="go!"/>

</form>

</body>

</html>

Hope this helps,

evnafets[/nobr]

evnafetsa at 2007-7-13 17:06:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi

I have already tried the trick that u told

but to my surprise when i click on the upload button (i mean submit button) for the FIRST time , the file object is being set to null (getting resetted) and for SECOND click it is being submitted with null in the file object.

The code that i am using here is

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>

<%@ taglib uri="/tags/struts-html" prefix="html" %>

<html:html locale="true">

<head>

<title>Struts File Upload Example</title>

<script language="javascript">

<!--

function promptForFile(theForm){

// popup the dialog prompt for a file

theForm.theFile.click();

// copy the value into a text field

theForm.fileLabel.value = theForm.theFile.value ;

}

//-->

</script>

<html:base/>

</head>

<body bgcolor="white">

<html:form action="/FileUpload" method="post" enctype="multipart/form-data">

<table>

<tr>

<td align="center" colspan="2">

<font size="4">Please Enter the Following Details</font>

</tr>

<tr>

<td align="left" colspan="2">

<font color="red"><html:errors/></font>

</tr>

<tr>

<td align="right"> File Name </td>

<td align="left"> <html:file property="theFile" style="position:relative;top:250px;right:-250px;"/> </td>

</tr>

<tr>

<td align="center" colspan="2">

<html:text property="fileLabel"/>

<html:button onclick="promptForFile(this.form);" property="UPLOAD" > Browse </html:button>

<html:button onclick="form.submit();" property="UPLOAD1">Upload </html:button>

</td>

</tr>

</table>

</html:form>

</body>

</html:html>

Please can u help

Regards

Siva Kumar Reddy P

sivakumarreddypa at 2007-7-13 17:06:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...