Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8328303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:23:43+00:00 2026-06-09T01:23:43+00:00

Using jQuery Mobile 1.7.1 for a button replacement of native input type=file . Code

  • 0

Using jQuery Mobile 1.7.1 for a button replacement of native input type="file".

Code works but forces a second request on the browse/open file bit.

What am I missing?

Same behavior on Chrome and FF (have not tried elsewhere).

<div id="fileInputButton"  data-role="button" data-icon="gear" style="width:150px;margin:0 auto; text-align:center">Import</div>

<div id="filename"></div>

<input style="opacity:0;" id="the_real_file_input" name="foobar" type="file">

 <script>
  $('#fileInputButton').click(function() {
    $('#the_real_file_input').click();
  });

  $('input[type=file]').bind('change', function() {
    var str = "";
    str = $(this).val();
    $("#filename").text(str);
  }).change();
 </script>

Thanks for your help!

UPDATE: Works fine in this fiddle http://jsfiddle.net/pg3Qf/ until JQuery Mobile is applied. (Thanks @wirey !)

FINAL UPDATE: This fixes the double trigger issue:

$('#fileInputButton').click(function(e) {
     e.stopImmediatePropagation();
     $('#the_real_file_input').click();
 });

And, this fixes the “C:\fakepath\” issue in Chrome and Safari:

str = $(this).val().replace(/C:\\fakepath\\/i, '');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:23:46+00:00Added an answer on June 9, 2026 at 1:23 am

    I don’t know why but using stopImmediatePropagation stops it from triggering twice. It doesn’t look like the event would be bubbling up to anything

    $('#fileInputButton').click(function(e) {
         e.stopImmediatePropagation();
         console.log('triggered');
         $('#the_real_file_input').click();
     });
    

    http://jsfiddle.net/pg3Qf/3/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to jquery mobile.I am displaying button using <input type=button id=result value=
I am using <input type=search /> textboxes in a jQuery Mobile site. JQM provides
I am creating an app using jQuery Mobile and PhoneGap. I delegate a button
i have some code using jquery mobile + phonegap and run it on my
I am creating a webapp for iPhone using jQuery Mobile and PhoneGap. Everything works
I’m using a jQuery mobile slider in a JQM dialog but it’s not being
I'm using PhoneGap and JQuery Mobile. I'm trying to use custom button icons. I
I'm using jquery mobile to building a site but when I click on a
i have an app in Blackberry, I was Build in using Jquery Mobile, but
I have a login page using jQuery Mobile which contains the following code: <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.