Jump to content
xisto Community
LuciferStar

Dynamic selecting form I did it.

Recommended Posts

Sorry there's no comment.

form.html

<html><head><script  language=javascript src="form.js"></script>[/br]</head>[br]<body onload=show(0)>[/br]</body></html>

form.js

[/br]mainboardcontent=new Array("8","abit","asus", "epox", "giga","intel","iwill","msi","others", 5,"intel", "via", "nvidia", "sis","others",4,"socket478","socket462(A)","socket370","other",3,"ddr","sdr","other",4,"soundblast","videocard","netcard","other");[br]harddcontent=new Array("6","maxtor","samsung", "hitach", "westerndata","seagate","others", 6,"40GB", "60GB", "80GB", "120GB", "160GB", "others",3,"5400rpm","7200rpm","other");[/br]cpucontent=new Array("4","Socket478","Socket462", "Socket370", "others", 6,"1M", "512KB", "256KB", "128KB", "64KB", "others",2,"111","222");[br]ramcontent=new Array("4","ddr","sdram", "rambus", "others", 4,"128M", "256KB", "512KB","others");[br][/br]selectdata=new Array("0","manual","1","1",  "1","CPU","2","0",  "2","MAINBOARD","5","0",  "3","RAM","2","0",  "4","HARDDRIVE","3","0");[br][/br][/br]function showdata(data,j)[br]{[/br]    if(j==0)[br]    {[/br]        max=data[j*data[0]];[br]        for(k=1;k<=max;k++)[/br]        {            [br]           document.write("<option value=\""+data[k]+"\">"+data[k]+"</option>");[/br]        }[br]    }[/br]    else[br]    {[/br]        old=++max;[br]        max+=data[max];[/br]        for(k=old+1;k<=max;k++)[br]        {            [br]           document.write("<option value=\""+data[k]+"\">"+data[k]+"</option>");[/br]        }[br]    }[/br]}[/br]function add(i)[br]{[/br]   for(var j=0;j<selectdata[i*4+2];j++)[br]   {[br][/br]      if(selectdata[i*4+3]=="0")[/br]      {[br]         document.write("<br><select name=\"select"+(j+1)+"\">");[br][/br]         switch(i)[/br]         {[br]             case "1": showdata(cpucontent,j);break;[/br]             case "2": showdata(mainboardcontent,j);break;[br]             case "3": showdata(ramcontent,j);break;[/br]             case "4": showdata(harddcontent,j);break;[br]             default:  document.write("<option value=\""+j+"\">"+j+"</option>");break;[/br]         }[br]         document.write("</select>");[/br]      }[br]      else  if(selectdata[i*4+3]=="1")[/br]      {[br]         document.write("<br><input name=\"which"+j+"\"></input>");[/br]      }[br]   }[/br]   document.write("<br><br><input type=submit></input>");[br]}[/br]function show(i)[br]{[/br]   document.write("<html><head><script language=javascript src=form.js></script></head><body>");[br]   document.write("<form name=\"form\" method=\"post\" action=\"\"><select name=\"which\" onchange='draw(this.options[this.selectedIndex].value);'>");[br][/br]   for(var x=0;x<19;x+=4)[br]   {[/br]      if(selectdata[x]==i)[/br]        document.write("<option selected value=\""+selectdata[x]+"\">"+selectdata[x+1]+"</option>");[br]      else[/br]        document.write("<option value=\""+selectdata[x]+"\">"+selectdata[x+1]+"</option>");[br]   }[/br]   document.write("</select><br>");[br]   if(i!=0)[br]   {[/br]      add(i);[br]   }[/br]   document.write("</form></body></html>");[br]}[/br]function init()[br]{[/br]   document.close();[br]}[/br]function draw(i)[br]{[/br]   init();[/br]   show(i);[br]}[/br]

Share this post


Link to post
Share on other sites

Good Contribution!!!!
Thanksssss!!!

I can put this form in my page??

thanks again


SURE! GO AHEAD!

You should modify the data:
such as
mainboardcontent=new Array("8","abit","asus", "epox", "giga","intel","iwill","msi","others", 5,"intel", "via", "nvidia", "sis","others",4,"socket478","socket462(A)","socket370","other",3,"ddr","sdr","other",4,"soundblast","videocard","netcard","other");

datastructure:
1 subselection: selectiongtitle=new Array("1","hello","hola");
2 subselections: selectiongtitle=new Array("1","hello","hola","2","ni hao","bonjour");
3 subselections: selectiongtitle=new Array("1","hello","hola","2","ni hao","bonjour","3","cell1","cell2","cell3");

Share this post


Link to post
Share on other sites

Hello !

 

In the same idea <_<, i discovered another script about customizable forms. You can find all what you know about it at this url Usable forms.

 

This script shows and hides form fields based on user actions. It is very interesting because it handles radio button and checkbox too !

 

Try the example on the page, you can test the script and observe the different results.

Share this post


Link to post
Share on other sites

You find it too <_<I recently used it in a professional project and it was very easy to integrate it in my existing development.Documentation about it (refer you to my last post) explains very clearly the manner of applying it in your own code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.