I have a form with several text inputs and one file input.
<table>
<tr>
<td>PlanID *</td>
<td><input type="file" name="file" id="file" placeholder="file" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>URL *</td>
<td><input type="text" name="url" id="url" placeholder="Image URL" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Height *</td>
<td><input type="number" name="height" id="height" placeholder="Height" />
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>width *</td>
<td><input type="number" name="width" id="width" placeholder="Width" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="sub" id="sub" value="Upload"
class="buttons"/></td>
<td><input type="reset" name="res" id="res" value="Cancel" class="buttons"/>
</td>
</tr>
</table>
I need to fill these URL, width and height fields in particular details by uploading an image. How could I do this??
My proposal is:
<img id="imgTogetWidthAndHeight" src="" style="display: none;"/>
In order to upload these data you need to wrap your table in a form or use and ajax call or plugin.
$(function () { $('#file').on('change', function(e) { var tmppath = URL.createObjectURL(e.target.files[0]); $("#imgTogetWidthAndHeight").attr('src',tmppath); var url = $(this).val(); $('#url').val(url); }); $("#imgTogetWidthAndHeight").on('load', function(e) { var width = parseInt($("#imgTogetWidthAndHeight").css('width')); var height = parseInt($("#imgTogetWidthAndHeight").css('height')); $('#width').val(width); $('#height').val(height); }); });
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <table> <tr> <td>PlanID *</td> <td><input type="file" name="file" id="file" placeholder="file"/><img id="imgTogetWidthAndHeight" src="" style="display: none;"/></td> </tr> <tr> <td> </td> </tr> <tr> <td>URL *</td> <td><input type="text" name="url" id="url" placeholder="Image URL"/></td> </tr> <tr> <td> </td> </tr> <tr> <td>Height *</td> <td><input type="number" name="height" id="height" placeholder="Height"/> </td> </tr> <tr> <td> </td> </tr> <tr> <td>width *</td> <td><input type="number" name="width" id="width" placeholder="Width"/></td> </tr> <tr> <td> </td> </tr> <tr> <td><input type="submit" name="sub" id="sub" value="Upload" class="buttons"/></td> <td><input type="reset" name="res" id="res" value="Cancel" class="buttons"/> </td> </tr> </table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.