.....javascript

  • conn2prince
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jun 28, 2005
  • Posts: 119
  • Status: Offline

Post November 14th, 2005, 4:57 am

Code: [ Download ] [ Select ]

<script language="JavaScript">
function funValidate()
{
        for(i=0;i<document.forms[0].elements.length;++i)
        {
            var elem = document.forms[0].elements[i];
            if (elem.type == "file")
            {
                if (elem.value == "") {
                    alert ("Please attach all your image files");
                    return ("");
                    }
            }
        }

      for (var i=0;i<document.frmUpload.tpictures.length;i++)
      {
        
            document.frmUpload.timg[i].src="file://" +document.frmUpload.tpictures[i].value;
            
           var retVal=showoptions(document.frmUpload.tpictures[i]);
             if(retVal){
                document.getElementById('submit').disabled=false;
             }else
             {
                document.getElementById('submit').disabled=true;
                alert('Only jpg files are allowed');
                return false;
             }
        }
}

function showoptions(what)
{
    var ext = what.value.substr(what.value.length - 3,3);
    if(ext=='jpg' || ext=='JPG')
    {
        document.getElementById('submit').disabled=false;
        return true;
    }
    else
    {
        return false;
    }
}

</script>
<body >
<form name="frmUpload">
<table>
                <? for($i=0;$i<3;$i++)
                        {
                ?>

           <tr class="as"> 
            <td colspan="2" bordercolor="#FFFFFF"><div align="left">Upload<br>
     <input type="file" name="tpictures" onChange="showoptions(this)" id="tpictures"/>
     <br>
     <img id="timg" name="timg" > <br>
    </div></td>
            <td bordercolor="#FFFFFF"><div align="center"><br>
    </div></td>
           </tr>
                <?    }    ?>
</table>
<input type="button" id="submit" name="submit" value="   Upload  " onClick="funValidate();" >
</form>
</body>
  1. <script language="JavaScript">
  2. function funValidate()
  3. {
  4.         for(i=0;i<document.forms[0].elements.length;++i)
  5.         {
  6.             var elem = document.forms[0].elements[i];
  7.             if (elem.type == "file")
  8.             {
  9.                 if (elem.value == "") {
  10.                     alert ("Please attach all your image files");
  11.                     return ("");
  12.                     }
  13.             }
  14.         }
  15.       for (var i=0;i<document.frmUpload.tpictures.length;i++)
  16.       {
  17.         
  18.             document.frmUpload.timg[i].src="file://" +document.frmUpload.tpictures[i].value;
  19.             
  20.            var retVal=showoptions(document.frmUpload.tpictures[i]);
  21.              if(retVal){
  22.                 document.getElementById('submit').disabled=false;
  23.              }else
  24.              {
  25.                 document.getElementById('submit').disabled=true;
  26.                 alert('Only jpg files are allowed');
  27.                 return false;
  28.              }
  29.         }
  30. }
  31. function showoptions(what)
  32. {
  33.     var ext = what.value.substr(what.value.length - 3,3);
  34.     if(ext=='jpg' || ext=='JPG')
  35.     {
  36.         document.getElementById('submit').disabled=false;
  37.         return true;
  38.     }
  39.     else
  40.     {
  41.         return false;
  42.     }
  43. }
  44. </script>
  45. <body >
  46. <form name="frmUpload">
  47. <table>
  48.                 <? for($i=0;$i<3;$i++)
  49.                         {
  50.                 ?>
  51.            <tr class="as"> 
  52.             <td colspan="2" bordercolor="#FFFFFF"><div align="left">Upload<br>
  53.      <input type="file" name="tpictures" onChange="showoptions(this)" id="tpictures"/>
  54.      <br>
  55.      <img id="timg" name="timg" > <br>
  56.     </div></td>
  57.             <td bordercolor="#FFFFFF"><div align="center"><br>
  58.     </div></td>
  59.            </tr>
  60.                 <?    }    ?>
  61. </table>
  62. <input type="button" id="submit" name="submit" value="   Upload  " onClick="funValidate();" >
  63. </form>
  64. </body>


using the above code images are displaying only in IE but not in any other browsers.please rectify it.........
please go thru this line too:
Code: [ Download ] [ Select ]
            document.frmUpload.timg[i].src="file://" +document.frmUpload.tpictures[i].value;

  1.             document.frmUpload.timg[i].src="file://" +document.frmUpload.tpictures[i].value;
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 14th, 2005, 4:57 am

  • Carnix
  • Guru
  • Guru
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 1101
  • Loc: Atlanta, GA
  • Status: Offline

Post November 14th, 2005, 6:37 am

Try specifying a default src value for the image, or perhaps use an innerHTML call to add the whole tag not just manipulate it's src attribute, or at least, provide a width and height value so the browser knows how big to render the img container. (my guess is, unless you're getting actual JavaScript error, the browsers are rendering the image, you just can't see it). You could also use a DOM call to create and append the tag to it's container as well.

If you validate your HTML against XHTML 1.0, most of these sorts of problems tend to work themselves out, by the way, I've decided to always validate new HTML and CSS against the W3C standard validators... It means some style changes to the way I like to code, but it's for the best...

I just wish there was a W3C JavaScript validator! (is there??)

.c
CARE Defending Dignity :: Fighting Poverty
Learn more at http://www.care.org/

Post November 14th, 2005, 8:48 am

conn2prince wrote:
".....There are two ways to write error-free programs. Only the third one works....."
I think you should go straight to #1. In Firefox, open Tools Menu -> JavaScript Console. What's the error, and which line of code does it happen to?

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 309 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2010 Unmelted, LLC. Driven by phpBB © 2010 phpBB Group.