...

View Full Version : Dynamically relating current Filename field to matching hidden field



tcadieux
10-18-2005, 09:24 PM
Using the below code, i manipulate the img Src when i browse using the Filename input field. However, the number of of filename fields and matching hidden fields is always unknown. I can easily create the two fields on the fly, however, i'm not sure how to manipulate the javascript code so that, say my user changes the file in filename field4, the hidden field4 would get updated also?



function DisplayImage(ImageName,ElementValue){
document.images[ImageName].src=ElementValue;
document.forms['myForm'].elements['hidden_ImgSrc'].value = ElementValue;


<input name="filename<%= x %>" type="File" id="filename<%= x %>" size="17" onChange="DisplayImageMultiples('MyPic<%= x %>',this.value)">
<input type="hidden" name="hidden_ImgSrc<%= x %>" value="<%=Filename(x)%>">

vwphillips
10-18-2005, 10:25 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var AddCnt=0;

function Add(){
h=document.getElementById('home');
c=document.getElementById('clone');
ips=c.getElementsByTagName('INPUT');
ip=[];
for (i=0;i<ips.length;i++){
ip[i]=ips[i].cloneNode(true);
h.appendChild(ip[i]);
if (i==1){
ip[i-1].id='FileTB'+AddCnt;
ip[i].id='HiddenTB'+AddCnt;
ip[i-1].ip=ip[i];
ip[i-1].onchange=function(){ this.ip.value=this.value; } // image swap can go in here
}
}

}
//-->
</script>

</head>

<body>
<input type="button" value="Add" onclick="Add();">
<div id="home" style="width:300px;" >
</div>
<div id="clone" style="position:absolute;visibility:hidden;" >
<!-- change to hidden when ready-->
<input type="file"><input type="text">
</div>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum