JAI MATADI all ..
i m doing validation in <input type=file> in which the user will only be able to select pictures .. if he/she has selected a document or another file .. he/she will get error ..
here is my code in which i m facing a bit problem ..
--------------------------------------------------
mytry.php
-------------------------------
<script type="text/javascript">
function ab(field,ext)
{
if (field.value.indexOf('.' + ext) == -1)
{
alert('Your uploaded file must be a .' + ext + ' type file.\nPlease select again.');
field.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" id="form1" method="post" enctype="multipart/form-data" onsubmit="return ab(f1,'jpg')">
<input type="file" name="f1" id="f1" />
<input type="submit" name="submit" id="submit" />
</form>
------------------------------------------------------------------------------------
m able to validate this code .. i want to add multiple validations (for gif,png) etc with this also ..
how can i do this .. if you have any query or link or yor own code .. please let me know .. as m able to get validation result here but for only single "jpg"
help me if you can ..
thank you ..
here m getting only the validation for (.jpg) but i want to add (gif,png) etc validations also in this ..
how can i do thiss ..
i have also tried this
<input type="file" accept="image/jpg, image/gif">
but nothing seems to be working
please help ..
@boeard678's
i have tried your code like this .. as m want to use || not &&
---------------------------------------------------------
<script type=text/javascript>
function ab(field)
{
if ((field.value.indexOf('.' + ext) == -1) || (field.value.indexOf('.jpeg') == -1 ))
{
alert('Your uploaded file must be a jpeg type file.\nPlease select again.');
field.focus();
return false;
}
return true;
}
</script>
---------------------------------------------------------
but its not working for me ..
help me
Bookmarks