Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some help about <input type="file"> 1

Status
Not open for further replies.

Excko

Programmer
Nov 10, 2003
7
CA
Hello everyone. I've got a form with 2 radio buttons(Yes, No) and an <input type=&quot;file&quot;>. Is there a way to make that if the Yes radio button is selected, the input cannot be empty? Since the value attribute does not work with the input type=&quot;file&quot; and that's I use the value field usaly to check if the field is empty, I don't know how to do it...
Please help.
Thank you in advance.
Excko
 
Excko,

Not sure what made you think you cannot test the value of a file box. The following code will, when the &quot;test&quot; button is pressed, alertan error if these 2 things are true:

1. The &quot;yes&quot; radio button is selected, and
2. The file box has nothing in it

Code:
<HTML>
<HEAD>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

	function testFileValue()
	{
		var formObj = document.forms['myForm'];
		if (formObj.yesNoRadios[0].checked && formObj.fileBox.value=='') alert('Filename cannot be empty!');
	}

//-->
</SCRIPT>

</HEAD>
<BODY>

<FORM NAME=&quot;myForm&quot;>
	<INPUT TYPE=&quot;file&quot; NAME=&quot;fileBox&quot;>
	<INPUT TYPE=&quot;radio&quot; NAME=&quot;yesNoRadios&quot; VALUE=&quot;yes&quot; CHECKED>Yes
	<INPUT TYPE=&quot;radio&quot; NAME=&quot;yesNoRadios&quot; VALUE=&quot;no&quot;>No
	<BR><BR><INPUT TYPE=&quot;button&quot; NAME=&quot;testButton&quot; VALUE=&quot;Test!&quot; onClick=&quot;testFileValue();&quot;>
</FORM>

</BODY>
</HTML>

Hope this helps!

Dan
 
Allright. Thanks Dan. The reason I thought that I could not use the value field is that I had read somewhere that we could not use the value field of a file input. That's all. ((Should've checked myself.))

Thnaks once again.
 
Excko, that's because you can read from it, but not write to it (with script).

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top