0

I need to get the value of the styleClass element in javascript. Page is in jsp with struts/html tag elements. jsp code is

<input type="hidden" class="filename" name="filename" value="<%= filename %>" />
                        <html:file property="testfile" styleClass="testfile"/>

and onclick of button I invoke the javascript

function fields() {
    var filename = jQuery('.filename');
    alert(filename);
    var testfile= jQuery('.testfile').val();
    alert(testfile);
    }

However in the firstcase(filename) I get [object object] returned and in second case I get "undefined". Can someone give some pointers on how to get the uploaded file name in jquery. Thanks

User
  • 135
  • 2
  • 4
  • 13

2 Answers2

1

If you want to get a value from an input:

var filename = $('.filename').val();

or

var filename = jQuery('.filename').val(); (same as above)

read more here -> jquery selector can't read from hidden field

Community
  • 1
  • 1
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
0

Try this

var testfile= jQuery('.testfile').attr('value');

It may be that your browser is preventing access to the value attribute for security reasons. Try both options in different browsers - Chrome, Firefox, IE, etc.

Rajesh J Advani
  • 5,585
  • 2
  • 23
  • 35