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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a DOM reference dynamically

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
Having a troubles grabbing a dynamic input name object when calling the onClick="" event. How do I apply the parameter "row" to the primaryFile object so that when a user clicks on the button, the function only uses that row?

function uploadFileWindow(row){
document.upLoadBy.primaryFile+row.value;
if(document.upLoadBy.primaryFile+row.value == null || document.upLoadBy.primaryFile.value == ""){
return;
}
document.upLoadBy.submit();

this is some dynamic row built, just take into account that this is a row incrementor <$rowCount$>

<input type="file" name="primaryFile<$rowCount$>" value="Browse" size=15>
<input type="button" value="upload" name="uploadFileSelected" onClick="JavaScript:uploadFileWindow('<$rowCount$>');">



Dano
What's your major malfunction
 
something like:

Code:
function uploadFileWindow(row){
    var r = document.forms['upLoadBy'].elements['primaryFile'+row].value;
    if(r == null || r == ""){
        return;
    }
    document.upLoadBy.submit();
}

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thanks Dude!

Taking the code a little further...the primary file object needs to be on the page. So I want to create a <div> cell that contains the file reference and update the value.

Code:
var f = document.forms['upLoadBy'].elements['primaryFile'+row].value;
		if(f == null || f == ""){
			alert("Please select a file to upload");
        		return;
    		}
//Is this what I need to do?
    		[b]document.all.prFile.primaryFile.value = f; [/b]
                   document.upLoadBy.submit();

...

<div id=prFile style="display:none">
	<input type=file name="primaryFile">
</div>


Dano
What's your major malfunction
 
1) avoid the "all" collection. it's ie only.
2) file type input fields cannot have their value set dynamically - it's a security risk.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top