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

2 Answers 2

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

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.