0
<input type="text" /> <input type="file" /> $('input[type=text]').click(function() { $('input[type=file]').trigger('click'); }); 

I can get browse option (open dialog box) when I click the test box. But I cannot get browse option when I trigger text box's click using jquery trigger method.

$('input[type=file]').trigger('click'); 

How do i solve this?

3
  • 2
    It works for me jsfiddle.net/jUsB4 Commented Mar 19, 2014 at 8:50
  • Working for me!! jsfiddle.net/FrFD3 Commented Mar 19, 2014 at 8:50
  • Looks like @user2039104 JS code is writen before html (DOM not ready yet) Commented Mar 19, 2014 at 8:51

3 Answers 3

2

What helped for me is to set the event-listener inside:

$(document).ready(function(){ $('input[type=text]').click(function() { $('input[type=file]').trigger('click'); }); }}; 

That used to do the trick for me. You might try it as well.

Sign up to request clarification or add additional context in comments.

Comments

0

You can wrap your code inside DOM ready handler $(function() {...}); to make sure your DOM elements are loaded properly before executing your jQuery code.

$(function( $('input[type=text]').click(function() { $('input[type=file]').trigger('click'); }); )}; 

1 Comment

Or just put your JS at the end of the page
0

My belief is your selector $('input[type=text]') is not selecting , give it some id and use it like

$("#text").click(function(){ $("#file").trigger("click"); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.