Vinod
Vinod

Reputation: 2311

Issue with HTML display format?

In my application I need to select the image. So I use input tag of type "file". The UI looks like the following image,

<input type="file" id="fileUploader">

enter image description here

How can I write the above input tag as <a> tag so that when clicking on the camera image I need to select the file,

<a href="#" onClick='#'><img src="img/camera.jpg"/></a>

Upvotes: 1

Views: 203

Answers (4)

Datz Me
Datz Me

Reputation: 955

I think this one is what you need

<img onclick="javascript:document.getElementById('myFile').click();" src="http://www.clker.com/cliparts/O/r/K/T/t/n/camera-icon-hi.png" style="width:50px;height:auto" />

<input type="file" id="myFile" style="display:none" />

I just hide my input file and let the onclick attribute of image show the dialog..

Just refer to my sample below.

http://jsfiddle.net/fbB46/

Upvotes: 0

Abhitalks
Abhitalks

Reputation: 28387

A better option than a would be to use a label with for, and keep the input hidden.

Demo: http://jsfiddle.net/abhitalks/GpsAJ/

Markup:

<label for="fileUploader" />
<input type="file" id="fileUploader" />

CSS:

#fileUploader {
    display: none;
}
label[for=fileUploader] {
    display: inline-block;
    width: 128px; height: 128px;
    cursor: pointer;
    background: url('your-camera-image-here') no-repeat left center;
}

Upvotes: 0

Aravin
Aravin

Reputation: 4108

Try like below for change the default file picker using jquery mobile

HTML is like:

<span class="ui-btn ui-icon-plus ui-btn-icon-left ui-corner-all fileinput-button">
<span>Pick File </span>
<input type="file" name="files" multiple data-role="none"/>
</span>

css is Like:

.fileinput-button {
      position: relative;
      overflow: hidden;
      float: left;
      margin-right: 4px;
    }
.fileinput-button input {
      position: absolute;
      top: 0;
      right: 0;
      margin: 0;
      opacity: 0;
      filter: alpha(opacity=0);
      transform: translate(-300px, 0) scale(4);
      font-size: 23px;
      direction: ltr;
      cursor: pointer;
    }

FIDDLE DEMO

Upvotes: 1

Mr7-itsurdeveloper
Mr7-itsurdeveloper

Reputation: 1631

Try this:

    $(function(){ 
     $('#anchorlink').click(function(){
    $(this).replaceWith('<input type="file" id="fileUploader" />'); 
$('#fileUploader').click(); 
    })
    });




<a href="#" id="anchorlink" >click<img src="stylish.png"/></a> 

http://jsfiddle.net/dQHh5/3/

Upvotes: 0

Related Questions