/    Sign up×
Community /Pin to ProfileBookmark

plug value into file text box after clicking on check box

Can a value be dynamically placed into a file input box after clicking on a check box? ….something like this:

[CODE]
function FillInFileName()
{
if (document.form1.NoPicture.checked == 1)
{
document.form1.file1.value== “C:Documents and SettingsFOLDERDesktopNoPic.jpg”;
}
}

<input type=”file” name=”file1″ size=25%> ‘Place value into the FILE TEXT BOX
‘after clicking on the checkbox
<input type=”checkbox” name=”NoPicture” onclick=”FillInFileName()”>
[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManJul 07.2007 — short answer appears to be no.

in testing, it appears that you can't pre-populate the value of a file input box, even if you manually set the "value" attribute in html.

MSDN confirms this behavior.. you'll note that there is no "value" attribute/property for "type=file" (unlike "type=text" which does have a "value" attribute)

the one caveat to this seems to be the fact that using the code below, you can alert the "value" of the file input if it's been entered in manually. perhaps theres a "hack" that can be worked since this truth exists..?

&lt;script&gt;
function FillInFileName()
{
if (document.form1.NoPicture.checked == 1)
{
alert(document.form1.file1.value);
document.form1.file1.value = "test";
alert(document.form1.file1.value);
}
}
&lt;/script&gt;

&lt;form name="form1"&gt;

&lt;input type="file" name="file1" size=25%&gt; 'Place value into the FILE TEXT BOX
'after clicking on the checkbox
&lt;input type="checkbox" name="NoPicture" onclick="FillInFileName()"&gt;

&lt;/form&gt;
Copy linkTweet thisAlerts:
@ASPSQLVBauthorJul 07.2007 — I tried the code you provided....that does not work.

Also, the form tag looks like this:
[CODE]<form method="post" enctype="multipart/form-data" action="GrabFishPic2.asp" name="form1">[/CODE]

The enctype="multipart/form-data" of the form tag is being used so the user can upload an image file when the submit button is clicked on. But, the only way the user can proceed is if there is a value in the file box.

Thats why I decided to have a checkbox......to fill in the file type box when clicked on.

So, my next question is: If there is a way I can validate the checkbox then I should be able to change the form tag from this [CODE]<form method="post" enctype="multipart/form-data" action="GrabFishPic2.asp" name="form1">[/CODE] to this [CODE]<form method="post" action="GrabFishPic2.asp" name="form1">[/CODE]????

This would bypass the uploading image process and just load the data into the database.

The only thing is, I am not sure on how the code should look to do this.

Would I need a client-side script or server-side script to do this ?




.
Copy linkTweet thisAlerts:
@Angry_Black_ManJul 07.2007 — Can a value be dynamically placed into a file input box after clicking on a check box?[/QUOTE]

short answer appears to be no.[/QUOTE]

I tried the code you provided....that does not work.[/QUOTE]

you can't pre-populate the value of a file input box[/QUOTE]

(that is, you [i]cannot[/i] dynamically populate the file input box... at all!)

i dont understand where you're going in regards to the "validating checkbox" thing...

you want to validate the checkbox if it says/indicates "______"? if it says "_______", that will tell you "_______" in regards to submitting the form?

im lorst!
Copy linkTweet thisAlerts:
@ASPSQLVBauthorJul 07.2007 — Explainging it in this forum is kind of tough

to upload a image you need

[CODE]<form method="post" enctype="multipart/form-data" action="GrabFishPic2.asp" name="form1">
[/CODE]


But, if there is no image to upload then that means only the data (text value) will be uploaded and saved to the database. I cannot do that while the form tag looks like this
[CODE]<form method="post" enctype="multipart/form-data" action="GrabFishPic2.asp" name="form1">
[/CODE]


So , I will validate the checkbox in javascript and upon the clicking of the checkbox, I will then send the user to the current page. Almost like the page is refreshing but actually a value is being passed.

That value being passed will then be validated in .ASP server side scripting.

Depending on what the value is will determine wether the fom tag will look like this:
[CODE]<form method="post" enctype="multipart/form-data" action="GrabFishPic2.asp" name="form1">
[/CODE]


or look like this:
[CODE]<form method="post" action="GrabFishPic2.asp" name="form1">
[/CODE]


Without the enctype="multipart/form-data" in the form tag I can now save strictly the data to the database and just bypass the uploading of an image process.

It all comes down to the user selected the "NO PICTURE" checkbox.

Hope this makes sense.
Copy linkTweet thisAlerts:
@Angry_Black_ManJul 07.2007 — okay, im with you now. sorry, im a little slow.

id make your asp page that you want to toggle your multipart thing look for a querystring value. if the value you parse with ASP is 0 or null, then response.write a multipart form.

if it is set to 1, then response.write a non-multipart form.

querystring information: http://www.w3schools.com/asp/coll_querystring.asp

a querystring in short is the bolded stuff below:

http://www.yahoo.com[B]?useMultipart=1[/B]
×

Success!

Help @ASPSQLVB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...