PDA

View Full Version : How to get the filepath value?



writeman
03-21-2007, 05:11 AM
hi all,
Bother u agan :)
I want to insert a list of filepath name in my DB by Web UI.
I want to reach two functions.
one:
When I press "type=file" input button to get the filepath value,
how to write the filepath value into the textarea at the same time?
two:
When my mouse clicks inner the textareare and I press the "type=button" input botton,
how to delete one line of the textarea?
Thanks for your helping.

<input type="file">
<textarea rows="10" cols="80"></textarea>
<input type="button" value="delete">

writeman
03-22-2007, 01:13 AM
hi all
I try to resolve the problem by myself and seems I reach the first function.
how to get the mouse position(row and col) in a textarea?
how to remove one line in the textarea?
Would somebody help me ><"

<script type="text/javascript">
function delpath(a){
//delete one line in the textarea where the mouse located
}
function addpath(){
var aa= document.getElementById('f01').value;
document.getElementById('f02').readOnly=false;
document.getElementById('f02').value=document.getElementById('f02').value + aa + "\r\n";
}
</script>

<p>
<input type="file" id="f01">
<input type="button" value="a d d" onclick="addpath()">
<input type="button" value="delete" onclick="delpath(this)">
</p>
<p><textarea rows="10" cols="80" id="f02">
D:\a.pl
D:\bkhomepage.bat
C:\b.txt
</textarea></p>

djr33
03-22-2007, 05:14 AM
<input type="file" onChange="myfield.value=this.value;">

"myfield" (change to what you want) is the name of the field you want to send the value. It could be a textarea, a text field, a hidden input, etc.

I think that's all you need.

However, I don't see the point of the textarea in this. If you want the user to be able to edit it, things could be very messy very fast.
If you allow the user to type, they could:
1. put something before the path in the textarea; how would you know which line to delete?
2. put something after the path; see (1).
3. change the text of the path, by accident or on purpose, meaning that it can't be found, even searching the contents of the textarea for the name directly.
4. they could for some reason type out another filepath, which might make things hard to find, etc.

It just seems like there isn't that much to gain.

I would suggest using an <input type="hidden"> for this, or a disabled text field or textarea.

If you DO need to delete the path, then the way to do that is to search the text of the textarea for the part that matches the current value of the textarea and clear it, but that is beyond my knowledge.

writeman
03-22-2007, 09:06 AM
Thanks all
I replace "textarea" to "select" and it works well.
I think there must be some method better to fit my desire.

<script type="text/javascript">
function delpath(){
var x=document.getElementById("f10")
if(x.selectedIndex > 0){
x.remove(x.selectedIndex)
}
}
function addpath(){
var aa= document.getElementById('ffile').value;
if(aa != ''){
var y=document.createElement('option');
y.text=aa;
var x=document.getElementById("f10");
try{
x.add(y,null); // standards compliant
}catch(ex){
x.add(y); // IE only
}
//y.selected= true;
}
}
</script>

<table border="1">
<tr>
<td colspan="2"><input type="file" id="ffile" size="88"></td>
</tr>
<tr>
<td><input type="button" value="add" onclick="addpath()"><br /><br />
<input type="button" value="delete" onclick="delpath()">
</td>
<td rowspan="2"><select id="f10" size="9" name="VFILE[]" multiple><option>===============================================</option></select></td>
</tr>
</table>