wuno
wuno

Reputation: 9865

Converting form values to JS

My goal is to create a photo path like this,

html: "<img src='[add-file-path-here]" + file["name"] + "' width='50' />"

This area

[add-file-path-here]

needs to be users/$username

$username is a hidden field in in the page so should be easily accessible. The form looks like this,

 <form id="upload" method="post" action="actions/upload.php" enctype="multipart/form-data">
<input type="hidden" name="username" value="<?php echo $username; ?>" id="username">

in this JS file how can I add the $username variable to the image path. That way no matter which user is logged in it always shows the rite path to that users images

So to be clear, in the html form I have a hidden field call $username, I want to create a img path in the JS file

 html: "<img src='[add-file-path-here]" + file["name"] + "' width='50' />"

How can I swap out [add-file-path-here] for users/$username

Upvotes: 0

Views: 33

Answers (1)

Philipp
Philipp

Reputation: 15629

Just read the form element value with jquery?

var path = "users/" + $("#username").val();
// ....
html: "<img src='" + path + file["name"] + "' width='50' />"

Upvotes: 2

Related Questions