Forum Moderators: open

Message Too Old, No Replies

input hide value

         

orion_rus

6:37 pm on Nov 29, 2004 (gmt 0)

10+ Year Member



Hello world i have a following code

<html>
<head>
<script>
function addtoarray(evt)
{if (evt) {evt=(evt)?evt:((event)?event:null);
elem=(evt.target)?evt.target:evt.srcElement;
elem.style.visibility='hidden';}
fileupl=document.getElementById('addingfiles');
fileupl.innerHTML("<br><input type='file'><input type='button' style='width:25px' onclick=addtoarray(event) value='+'>";
}
</script>
</head>
<body>
<div id="addingfiles">
</div>
<script>addtoarray();</script>
</body>
</html>

all works fine but if i add a file and when press +, i losses value in a input field what typed before. if even i have all fields fillen and press plus i loose all values(
Anybody can help?

Bernard Marx

8:56 pm on Nov 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The innerHTML way is no good...

Remember that it rewrites the HTML. Perhaps that should include the values, but it doesn't. File inputs do behave in a special way because of security concerns. For instance, you can't set a value on a file input via script.

Either way, you didn't need the event querying part of the function. Using 'this' in the event handler for the + button will achieve the desired effect.

This should work:

[pre]
<html>
<head>
<script>
function addtoarray(elem)
{
elem.style.visibility='hidden';
var parent = elem.parentNode;
parent.appendChild( document.createElement('<input type="file">'));
parent.appendChild( document.createElement(
'<input type="button" style="width:25px" onclick="addtoarray(this)" value="+">'
));
}
</script>
</head>
<body>
<div id="addingfiles" style="width:300px;"><!--width is for wrapping-->
<input type="file">
<input type="button" style="width:25px" onclick="addtoarray(this)" value="+">
</div>
</body>
</html>
[/pre]