Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 22nd, 2003, 07:19 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrive text from input type field of html file??

Hi all friends,

I want to retrive text from input type field of html file so that I can send it to my servlet as a query string with url on onClick event of button.I don't want to use form tag using submit button.Can any one plz give me some code for that.Eagerly waiting for someone reply.

Regards
Bikash

  #2 (permalink)  
Old July 22nd, 2003, 07:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Arlington, TX, USA.
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

You may have already tried this. I think that if you identify the text field as a hidden field within your HTML code then you can setup a variable in your javascript and use it that way(?).
  #3 (permalink)  
Old July 22nd, 2003, 01:15 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If your field has an id of 'txtFile' then:
Code:
var sFileName = document.getElementById("txtFile").value;
will retrieve the value. This value is read only for security reasons.


--

Joe
  #4 (permalink)  
Old July 23rd, 2003, 05:26 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Can u please tell me how i can assign 'var sFileName' to a string variable because I want to send file name with url of my servlet as query string.And in my servlet Iam taking that file name[String str=req.getParameter("name");] Below r my codes:-

<script>
var sFileName = document.getElementById("txtFile").value;
var path="http://127.0.0.1:8080/examples/servlets/NetRecvServlet";
function sendFile(){
document.form.action=path+"?"+"&name=sFileName";
}
</script>

<body>
<form method="POST" enctype="multipart/form-data">

<p>Select file to send:<input name="Button" type="file" class="file1" id="txtFile" size="30"></p>

<p><input name="sendfilebtn" type="button" class="btn" id="sendfilebtn" value="Send File" onClick="sendFile()"></p>

<input name="suspendbtn" type="button" class="btn" id="suspendbtn" value="Suspend" onClick="suspendFile()">

<input name="resumebtn" type="button" class="btn" id="resumebtn" value="Resume" onClick="resumeFile()">

</form>
</body>

Thanks & Regards
Bikash

  #5 (permalink)  
Old July 23rd, 2003, 06:15 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well I can't see how how that information will help but, assuming this is the first or only form:
Code:
function sendFile()
{
var sFileName = document.getElementById("txtFile").value;
var sSafeFileName = encodeURIComponent(sFileName);
//for older browsers use
//var sSafeFileName = escape(sFileName);

var path="http://127.0.0.1:8080/examples/servlets/NetRecvServlet";
document.form[0].action=path+"?"+"&name=" + sSafeFileName;
document.form[0].submit();
}
--

Joe
  #6 (permalink)  
Old July 23rd, 2003, 06:24 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry, in above code should be forms not form:
Code:
...
document.forms[0].action=path+"?"+"&name=" + sSafeFileName;
document.forms[0].submit();
--

Joe
  #7 (permalink)  
Old July 24th, 2003, 12:20 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I have tried as per ur given code but i couldn't slove my problem,now my html couldn't connect my servlet.Now Iam explaining what Iam trying to do.I am trying to develop one uploading application for that Iam using html for client interface.And in my uploading application i want to give 'Resume' and 'Suspend' facility on html client interface so that user can Suspend Uploading of file and can Resume uploading of that file.I have already developed this uploading application using swing and servlet for intranet now i want to put this application on web thats why iam using html for client interface.Can u plz guide me how I can do this in html.Eagerly waiting for ur reply.

Thanks&Regards
Bikash



  #8 (permalink)  
Old July 29th, 2003, 03:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well all you're doing at the moment is passing a file name to a servlet. Do you want an HTML page that uploads a file to a servlet but with the additional features of suspend and resume? Where will the servlet and web page sit, on the same web server? What input does the servlet need?

--

Joe
  #9 (permalink)  
Old July 30th, 2003, 12:32 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe,

Do you want an HTML page that uploads a file to a servlet but with the additional features of suspend and resume?

Ya,I want to give facility on html client interface so that user can suspend and reume of file uploading.Is it possible to give facility of suspend and Resume on html page.To suspend my uploading servlet needs one variable value 'false'.And for resume my servlet needs File name and size of file and destination folder name so that my servlet first search that file in that folder and if file.exists(),it returns that file size and my client interafce reads remaining portion of that file by skipping that portion which already written by servlet in destination folder.

Where will the servlet and web page sit, on the same web server? What input does the servlet need?

Html on apache web server and servlet on Tomcat server.If it is require to keep both html and servlet on same server then I can do it.Servlet needs Name & Size of File,System date&time and destination folder name.My servlet also maintain the report of uploaing of file in SQL database.

Can you please help me to slove my problem.Eagerly waiting for ur reply.

Thanks & Regards
Bikash

  #10 (permalink)  
Old July 30th, 2003, 03:11 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry to keep asking but how will the servlet have access to the file with only its path? Surely the file will reside on the client, either a fixed disk or a network mapping. The servlet will not be able to locate it with this information.

--

Joe




Similar Threads
Thread Thread Starter Forum Replies Last Post
asp3.0 input text field naeem_ul_hussan Classic ASP Professional 5 July 31st, 2007 08:11 AM
input type="file" grstad Classic ASP Basics 24 January 31st, 2007 07:28 PM
Focus on a text input field fizzerchris Classic ASP Basics 0 December 16th, 2005 09:20 PM
input type file darkhalf Javascript 1 October 29th, 2005 02:17 AM
<input type="File"> - Specify File Type and Path gp_mk Classic ASP Basics 2 August 2nd, 2004 03:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.