Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
well i put in a javascript code and it looked quite right at first but when i try to use it it fails and if you can see i even tried putting these two in different javascript files but still it only read only one of them.

JavaScript
function setValue(){
myVariable= document.forms["myform"]["gname"].value;
myVariable2= document.forms["myform"]["gpc"].value;
myVariable3= document.forms["myform"]["procesor"].value;
myVariable4= document.forms["myform"]["ram"].value;
myVariable5= document.forms["myform"]["os"].value;
var gname = ["Prince of Persia: The Forgotten Sands"];
var gpc = ["GeForce 8600 GTS 512MB", "GeForce 8800 Ultra", "GeForce 8800 GTX", "GeForce 8800 GTS (640 MB)", "GeForce 8800 GTS (512 MB)", "GeForce 8800 GTS (320 MB)", "GeForce 8800 GT", "GeForce 8800 GS", "GeForce 8600 GTS", "9800 GX2 (1 GB)", "9800 GTX (512MB GDDR3)", "9800 GTX+ (512MB GDDR3)", "9800 GT(512MB GDDR3)", "9600 GT(512MB)", "9600 GSO (384MB)", "9500 GT (256MB GDDR3)", "GeForce GTX 590", "GeForce GTX 580", "GeForce GTX 570", "GeForce GTX 560", "GeForce GTX 560", "GeForce GTX 550", "GeForce GT 520", "GeForce GTX 560" , "GeForce GTX 560" , "GeForce GTX 555" , "GeForce GT 545 GDDR5" , "GeForce GT 545 DDR3" , "GeForce GT 530" , "GeForce GT 520" , "GeForce 510" , "GeForce GTX 400 GPUs" , "GeForce GTX 480" , "GeForce GTX 470" , "GeForce GTX 460" , "GeForce GTX 465" , "GeForce GTS 450" , "GeForce GT 440" , "GeForce GT 430" , "GeForce GTX 460" , "GeForce GTS 450" , "GeForce GT 440" , "GeForce GT 430" , "GeForce GT 420" , "GeForce 405" , "GeForce GT 340" , "GeForce GT 330" , "GeForce GT 320","GeForce 315"];
var procesor = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+"];
var ram = ["3 GB", "2 GB", "1 GB"];
var os = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
var canRun = false;
 {
for(i=0;i<gname.length;i++)
        if (myVariable === gname[i]) //changed from 0 to i here
        {   
for (j=0;j<gpc.length;j++)
    {
        if (myVariable2 === gpc[j]) //changed from 0 to i here
        {
for (k=0;k<procesor.length;k++)
    {
        if (myVariable3 === procesor[k]) //changed from 0 to i here
        {  
for (h=0;h<ram.length;h++)
    {
        if (myVariable4 === ram[h]) //changed from 0 to i here
        {  
for (l=0;l<os.length;l++)
    {
        if (myVariable5 === os[l]) //changed from 0 to i here
{   
            canRun = true;  
        }
    }
}
}
}
}
}
}
}
}

    if (canRun)
    {   
        alert("yes this game can run");
    }
    else 
    {       
        alert("No, This game cannot run");
    }
};


function setValue(){

myVariable= document.forms["myform"]["gname"].value;
myVariable2= document.forms["myform"]["gpc"].value;
myVariable3= document.forms["myform"]["procesor"].value;
myVariable4= document.forms["myform"]["ram"].value;
myVariable5= document.forms["myform"]["os"].value;
var a = ["Gears of War"];
var b = ["ATI Radeon 5000 Series", "ATI Radeon 4000 Series", "ATI Radeon 3000 Series", "ATI Radeon HD 2900 Overview", "ATI Radeon HD 2600 Overview", "ATI Radeon HD 2400 Overview", "ATI Radeon X1950 Series", "ATI Radeon X1900 Series", "ATI Radeon X1800 Series", "ATI Radeon X1650 Series", "ATI Radeon X1600 Series", "ATI Radeon X1550 Series", "ATI Radeon X1300 Series", "ATI Radeon X1050 Series"];
var c = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+"];
var d = ["3 GB", "2 GB", "1 GB"];
var e = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
var canRun = false;
for(m=0;m<a.length;m++)
{
        if (myVariable === a[m]) //changed from 0 to i here
        {   
for (n=0;n<b.length;n++)
    {
        if (myVariable2 === b[n]) //changed from 0 to i here
        {
for (o=0;o<c.length;o++)
    {
        if (myVariable3 === c[o]) //changed from 0 to i here
        {  
for (p=0;p<d.length;p++)
    {
        if (myVariable4 === d[p]) //changed from 0 to i here
        {  
for (q=0;q<e.length;q++)
    {
        if (myVariable5 === e[q]) //changed from 0 to i here
{   
            canRun = true;  
        }
        
    }
}
}
}
}
}
}
}
}

if (canRun)
    {   
        alert("yes this game can run");
    }
    else 
    {       
        alert("No, This game cannot run");
    }
};
Posted
Comments
Nick Fisher (Consultant) 22-Oct-13 11:17am    
I have run this code in IE8 and it runs fine, popping up the message 'yes this game can run'. What's the problem with it exactly? You need to elaborate more by telling us where the function itself is being called, and showing how your form fields are defined.
Member 10352445 22-Oct-13 12:56pm    
i am sorry i should have clearly mentioned my problem you see i have added all ati graphics in gears of war array and nvidia graphics in prince of persia array and i want that when i select prince of persia and if i select an nvidi graphic card then it should print out this will run and if i select gears of war and select an ATI graphic card it should say it will run but if i select prince of persia and an ati graphic card it should say this will not run well now the problem is that if i select gears of war and select an ati graphic card it says this can run but when i select prince of persia and an nvidia graphic card it says this will not run please help me with that.

Just a quick comment on the logic you've used - if something should happen if all of the conditions are met, then it shouldn't happen if a single one of those conditions is not met.

I.e - It's common practise to set a variable first then alter it if a condition isn't met - it's much nicer to read than all those nested for/if loops.

E.g
C++
// returns true if all conditions are met
// false otherwise
function checkConditions()
{
	var isOk = true;
	var a=1, b=1, w=2, x=2, y=3, z=4;
	
	if (a != b)
		isOk = false;
		
	if (w != x)
		isOk = false;
		
	if (y != z)
		isOk = false;
	
	return isOk;
}

// returns true if all conditions are met
// false otherwise
// modified to exit as soon as a condition fails - this may save much or little time, it depends on the complexity of the conditions
function checkConditions()
{
//	var isOk = true;
	var a=1, b=1, w=2, x=2, y=3, z=4;
	
	if (a != b)
		return false;	//isOk = false;
		
	if (w != x)
		return false;	//isOk = false;
		
	if (y != z)
		return false;	//isOk = false;
	
	return true;
}
 
Share this answer
 
here is how i myself fixed it

C#
function setValue(){
myVariable= document.forms["myform"]["gname"].value;
myVariable2= document.forms["myform"]["gpc"].value;
myVariable3= document.forms["myform"]["procesor"].value;
myVariable4= document.forms["myform"]["ram"].value;
myVariable5= document.forms["myform"]["os"].value;
var gname = ["Prince of Persia: The Forgotten Sands"];
var gpc = ["GeForce 8600 GTS 512MB", "GeForce 8800 Ultra", "GeForce 8800 GTX", "GeForce 8800 GTS (640 MB)", "GeForce 8800 GTS (512 MB)", "GeForce 8800 GTS (320 MB)", "GeForce 8800 GT", "GeForce 8800 GS", "GeForce 8600 GTS", "9800 GX2 (1 GB)", "9800 GTX (512MB GDDR3)", "9800 GTX+ (512MB GDDR3)", "9800 GT(512MB GDDR3)", "9600 GT(512MB)", "9600 GSO (384MB)", "9500 GT (256MB GDDR3)", "GeForce GTX 590", "GeForce GTX 580", "GeForce GTX 570", "GeForce GTX 560", "GeForce GTX 560", "GeForce GTX 550", "GeForce GT 520", "GeForce GTX 560" , "GeForce GTX 560" , "GeForce GTX 555" , "GeForce GT 545 GDDR5" , "GeForce GT 545 DDR3" , "GeForce GT 530" , "GeForce GT 520" , "GeForce 510" , "GeForce GTX 400 GPUs" , "GeForce GTX 480" , "GeForce GTX 470" , "GeForce GTX 460" , "GeForce GTX 465" , "GeForce GTS 450" , "GeForce GT 440" , "GeForce GT 430" , "GeForce GTX 460" , "GeForce GTS 450" , "GeForce GT 440" , "GeForce GT 430" , "GeForce GT 420" , "GeForce 405" , "GeForce GT 340" , "GeForce GT 330" , "GeForce GT 320","GeForce 315"];
var procesor = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+"];
var ram = ["3 GB", "2 GB", "1 GB"];
var os = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
var canRun = false;
 {
for(i=0;i<gname.length;i++)
        if (myVariable === gname[i]) //changed from 0 to i here
        {
for (j=0;j<gpc.length;j++)
    {
        if (myVariable2 === gpc[j]) //changed from 0 to i here
        {
for (k=0;k<procesor.length;k++)
    {
        if (myVariable3 === procesor[k]) //changed from 0 to i here
        {
for (h=0;h<ram.length;h++)
    {
        if (myVariable4 === ram[h]) //changed from 0 to i here
        {
for (l=0;l<os.length;l++)
    {
        if (myVariable5 === os[l]) //changed from 0 to i here
{
            canRun = true;
        }
    }
}
}
}
}
}
}
}
}


var a = ["Gears of War"];
var b = ["ATI Radeon 5000 Series", "ATI Radeon 4000 Series", "ATI Radeon 3000 Series", "ATI Radeon HD 2900 Overview", "ATI Radeon HD 2600 Overview", "ATI Radeon HD 2400 Overview", "ATI Radeon X1950 Series", "ATI Radeon X1900 Series", "ATI Radeon X1800 Series", "ATI Radeon X1650 Series", "ATI Radeon X1600 Series", "ATI Radeon X1550 Series", "ATI Radeon X1300 Series", "ATI Radeon X1050 Series"];
var c = ["Core 2 Duo E4500 2.2GHz", "Athlon 64 X2 Dual Core 4400+"];
var d = ["3 GB", "2 GB", "1 GB"];
var e = ["Windows Xp", "Windows 7", "Windows Vista", "Windows 8"];
for(m=0;m<a.length;m++)
{
        if (myVariable === a[m]) //changed from 0 to i here
        {
for (n=0;n<b.length;n++)
    {
        if (myVariable2 === b[n]) //changed from 0 to i here
        {
for (o=0;o<c.length;o++)
    {
        if (myVariable3 === c[o]) //changed from 0 to i here
        {
for (p=0;p<d.length;p++)
    {
        if (myVariable4 === d[p]) //changed from 0 to i here
        {
for (q=0;q<e.length;q++)
    {
        if (myVariable5 === e[q]) //changed from 0 to i here
{
            canRun = true;
        }

    }
}
}
}
}
}
}
}
}

if (canRun)
    {
        alert("yes this game can run");
    }
    else
    {
        alert("No, This game cannot run");
    }
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900