开发者

Javascript selectbox

开发者 https://www.devze.com 2023-02-05 03:31 出处:网络
Hi I\'m new to javascript and am trying to create a form with some options. I\'m building a site for a Wood Floor Restoration Company, they want a form where the user can fill in a few options and ge

Hi I'm new to javascript and am trying to create a form with some options.

I'm building a site for a Wood Floor Restoration Company, they want a form where the user can fill in a few options and get a rough price guide.

So I've created a form using SmartFormer but having probs

Using a Listbox with 5 different types of floor, say you select Pine Floor in the List box, it then lists the the type of finish of the current floor in a Select box, all what I want to do is set different values to each of the finishes. Currently if you select Finish - Original Never Sanded for example they currently all give the same value (500). How do I change it so if you select Waxed or Oiled they have different values.

Below is the script so far, if anyone can tell me what I need to change or add I will be extremly grateful, and so will my hair line as I just dont have much more left to pull out.

Thanks

function add_item(id,val,_obj) {
 tmp=document.createElement("OPTION");http://localhost/mcmullan/administrator/components/com_smartformer/plugins/edit_area/images/spacer.gif
 tmp.value=id;
 tmp.text=val;
 _obj.options.add(tmp); 
}
function boards_change(field) {
 if (field.selectedIndex==0) { 
  while ({%id28}.options.length>0) {%id28}.remove(0);
  add_item(0,'-- Please select --',{%id28});
  add_item(1,'Pine Boards- Original Never Sanded',{%id28});
  add_item(2,'Pine Boards- Sanded & Varnishe开发者_开发问答d/Lacquered',{%id28});
  add_item(3,'Pine Boards- Sanded & Varnished/Lacquered',{%id28});
  {%id31}.value='500';
 } else 
 if (field.selectedIndex==1) {  
  while ({%id28}.options.length>0) {%id28}.remove(0);
  add_item(0,'-- Please select --',{%id28});
  add_item(1,'Mosaic - Sanded & Varnished/Lacquered',{%id28});
  add_item(2,'Mosaic - Sanded & Varnished/Lacquered',{%id28});
  add_item(3,'Mosaic - Sanded & Varnished/Lacquered',{%id28});
  {%id31}.value='600';
 } else
 if (field.selectedIndex==2) { 
  while ({%id28}.options.length>0) {%id28}.remove(0);
  add_item(0,'-- Please select --',{%id28});
  add_item(1,'Herringbone - Sanded & Varnished/Lacquered',{%id28});
  add_item(2,'Herringbone- Sanded & Varnished/Lacquered',{%id28});
  add_item(3,'Herringbone- Sanded & Varnished/Lacquered',{%id28});
  {%id31}.value='700';
 } else
 if (field.selectedIndex==3) { 
  while ({%id28}.options.length>0) {%id28}.remove(0);
  add_item(0,'-- Please select --',{%id28});
  add_item(1,'Hardwood - Sanded & Varnished/Lacquered',{%id28});
  add_item(2,'Hardwood - Sanded & Varnished/Lacquered',{%id28});
  add_item(3,'Hardwood - Sanded & Varnished/Lacquered',{%id28});
  {%id31}.value='800';
 } else
 if (field.selectedIndex==4) { 
  while ({%id28}.options.length>0) {%id28}.remove(0);
  add_item(0,'-- Please select --',{%id28});
  add_item(1,'Engineered Boards- Sanded & Varnished/Lacquered',{%id28});
  add_item(2,'Engineered Boards- Sanded & Varnished/Lacquered',{%id28});
  add_item(3,'Engineered Boards- Sanded & Varnished/Lacquered',{%id28});
  {%id31}.value='900';
 }
 calculate_price();
}
function calculate_price() {
 if({%id31}.value-0>0) {%id52}.value=({%id32}.selectedIndex+1)*({%id31}.value-0)+({%id35}.selectedIndex+1)*({%id31}.value-0)*10;
  else {%id52}.value='';
}


Try this: http://jsfiddle.net/jchandra/Q8J7F/

I am not sure how SmartFormer thing work, but I think I reconstructed enough detail to give you an idea on how to continue.

0

精彩评论

暂无评论...
验证码 换一张
取 消