JavaScript - rename "Browse" of type=file

Asked By Little Bee on 28-Nov-05 02:26 AM
I am replacing the default "Browse..." button for input type=file. This works fine except that the form will only submit after the SUBMIT button is clicked twice. Any ideas on why this is happening or a workaround? Many thanks! 
<html>
<head></head>
<body>
<form name="test_form" method="post" action="test.jsp"> 
<input type=file name=browse style="display: none;">
<input type=text name=file>
<input type=button value="Select a File..." onClick="browse.click();file.value=browse.value;"> 
<!-- must be clicked twice for the form to submit! -->
<input type=submit value="Submit The Form Now!">
</form> 
</body> 
</html>

try this

Asked By Janaga Rathinam on 02-Dec-05 02:31 AM
<html>
<head></head>
<body>
<form name="test_form" method="post" action="test.jsp">
<input type="text" name="file">
<input type="button" 
      style="font-style:veranda; font-size:12px; font-weight:bold;text-transform:lowercase;color:white;background-color:#999999;height:22px;border-style:ridge;text-align:center;" 
      onClick="document.dummy.browse.click();this.form.file.value=document.dummy.browse.value;" 
      value="Select a File...">        
<br><br>
<!-- must be clicked twice for the form to submit! -->
<input type="submit" 
      name="submit"
      value="Submit The Form Now!"
      style="font-style:veranda; font-size:12px;" >
</form>
<form name="dummy">
<input type="file" name="browse" style="display:none;">
</form>
</body>
</html>

it works thank you so much

Asked By Little Bee on 04-Dec-05 07:51 PM
brilliant ! thanks a lot.

how to get the object file in test jsp ?

Asked By Little Bee on 04-Dec-05 09:51 PM
when submit "test_form", test.jsp is unable to get the object file "browse". null pointer is encountered. any idea how test.jsp can upload file to server ? 
thanks...
Sasi replied to Little Bee on 28-Sep-10 05:51 AM
Hi,

This is one of the good solutions, but this is not working other than IE. Can anybody help me out?

Thanks