Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Dynamically relating current Filename field to matching hidden field

    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?

    Code:
    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)%>">

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •