Link to home
Start Free TrialLog in
Avatar of Chris Bottomley
Chris BottomleyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBS to Javascript 2

I have a routine used by a simple development page that I need converting to work as Javascript.  As it is it effectively concatenates two strings:

strBuild is the concateneated string so far.
strItem is the string to add and could be blank or a constant "File Not Required"
If the string is blank, null or not required then the original strBuild string is returned otherwise if strbuild is not blank a comma is added in preparation for adding the stritem then the string is returned as the function result.

Chris
function retFileNames(strBuild, strItem)

	if stritem = "File Not Required" or stritem = ""  or stritem = "None" then
		retFileNames = strbuild
	else
		if strbuild = "" then
			retFileNames = stritem
		else
			retFileNames = strBuild & "," & stritem
		end if
	end if

end function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of iGottZ
iGottZ
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Bottomley

ASKER

Some of the variables were the wrong case, but thanks for the heads up I think I have corrected all, now when I get to (other post) the line:

strFileName = InObj.value;

All is well, used an alert to demonstrate the file name, but it never passes any data and seems to fall over since I set an alert after the line:

 strFileNames = retFileNames(strFileNames, strFileName);

And this alert is not generated .. the rest of the page then falls over for the lack of data.  I include the case corrected?

Case for the combo titles is correct.  The combos return a file path as something alomg the following lines:

startpoint\subfolder\subsubfolder\displayedcombostring.doc

Where startpoint is the root of the server

Chris
function GenerateFile() {
	var MainFrm = parent.document.frames("main") || false;
	if (!MainFrm) {
		alert("Couldn't get frame");
		return;
	}
	var DocObj = MainFrm.document;
	var InObj = DocObj.getElementById("combo1");
		alert("Step 3");
	strFileName = InObj.value;
		alert("Step 4 :> " + strFileName);
	strFileNames = retFileNames(strFileNames, strFileName);
		alert("Step 5");
	
	var InObj = DocObj.getElementById("combo2");
	strFileName = InObj.value;
	strFileNames = retFileNames(strFileNames, strFileName);
	
	strfilenames = strfilenames.replace(/\r\n/gi, ",");
	alert(strfilenames);

	document.getElementById("files").value = strfilenames;
}

function retFileNames(strBuild, strItem) {
		alert("Step 5a");
	if (strItem == "File Not Required" || strItem == "" || strItem == "None") {
		return strBuild;
	} else {
		if (strBuild == "") {
			return strItem;
		} else {
			return strBuild + "," + strItem;
		}
	}
}

Open in new window

in line 12 you pass in strFileNames.
still i dont see where you have initialized that variable.
if you have not initialized this variable before argumenting it into retFileNames, you pretty much found the issue.

what browser are you using? if firefox / chrome / opera you could use the debug console to see where the errors are.

could you post required code for this to run so i could debug this for errors?
Unfortunately i'm not at work so I am working with some but not all the files .. and they would need further redacting to do so - that would therefore mean a postponement till Monday... hopefully not a biggie but I sense it is so darned close!  

As for strFileNames, I wasn't initialising it as I didn't think it critical, but have done so and after fixing a few more issues am seeing the strFileNames output at line 22 fine.  The next thing was the form hidden parameter files was actually Files but on correcting I still nothing into the form parameter ... and from VBS at the same point the transfer of the string is fine and therefore it would seem to lie with the line:

document.getElementById("files").value = strfilenames;
corrected in code as:
document.getElementById("Files").value = strFileNames;

Chris
Correction, found another bad case variable, the failure mode is a bit dramatic when it happens but thanks it's working ... will try next week on FF but for now it has switched from VBS to JS on IE and that's what I was looking for so many thanks.

Chris
Partial accuracy since there were some case errors in teh supplied code but since the info was supplied re the sensitivity to case it is churlish to say anything other than accurate.

Chris