Jump to content

[SOLVED] dynamic table (for canda and u.s. shipping info)


M.O.S. Studios

Recommended Posts

hey guys,

 

basicly i have this code on my site

 

<form name="shipform" action="test.php" method="GET">

<select name="ship_con" onChange="updateship_pro(this.selectedIndex)">
<option value="">Please select</option>
<option value="Canada">Canada</option>
<option value="U.S.A.">USA</option>
</select>

<select name="ship_pro">
</select>

<input type="submit" Value="test">
</form>

<script type="text/javascript">

var ship_conlist=document.shipform.ship_con
var ship_prolist=document.shipform.ship_pro

var ship_pro=new Array()
ship_pro[0]=""
ship_pro[1]=["Ontario|ON", "Quebec|QC", "Nova Scotia|NS", "New Brunswick|NB", "Manitoba|MB", "British Columbia|BC", "Prince Edward Island|PE", "Saskatchewan|SK", "Alberta|AB", "Newfoundland and Labrador|NU", "Yukon|YT"]
ship_pro[2]=["state1|state1", "state2|state2"]


function updateship_pro(selectedship_pro){
ship_prolist.options.length=0
for (i=0; i<ship_pro[selectedship_pro].length; i++)
ship_prolist.options[ship_prolist.options.length]=new Option(ship_pro[selectedship_pro][i].split("|")[0], ship_pro[selectedship_pro][i].split("|")[1])
}


</script>

 

i would like to have the 3 <input type="text"> on this same form, 2 of them apear if ship_con = canada and only the 3rd if ship_con = U.S.A

 

any ideas?

<html>
<head>

<script type="text/javascript">

  var ship_pro=new Array()
  ship_pro[0]=''
  ship_pro[1]=['Ontario|ON', 'Quebec|QC', 'Nova Scotia|NS', 'New Brunswick|NB', 'Manitoba|MB', 'British Columbia|BC', 'Prince Edward Island|PE', 'Saskatchewan|SK', 'Alberta|AB', 'Newfoundland and Labrador|NU', 'Yukon|YT']
  ship_pro[2]=['state1|state1', 'state2|state2']

  function updateship_pro(selectedship_pro)
  {
    var ship_prolist=document.shipform.ship_pro;

    ship_prolist.options.length = 0;
    for (var i=0; i<ship_pro[selectedship_pro].length; i++)
    {
      option = ship_pro[selectedship_pro][i].split('|');
      ship_prolist.options[ship_prolist.options.length] = new Option(option[0], option[1]);
    }
    document.getElementById('address_fields').style.visibility = (selectedship_pro==0) ? 'hidden' : '';
    document.getElementById('addr_3').style.visibility = (selectedship_pro!=2) ? 'hidden' : '';
  }

</script>
</head>

<body>
<form name="shipform" action="test.php" method="GET">
  <select name="ship_con" onChange="updateship_pro(this.selectedIndex)">
    <option value="">Please select</option>
    <option value="Canada">Canada</option>
    <option value="U.S.A.">USA</option>
  </select><br>

  <span id="address_fields" style="visibility:hidden;">
  <select name="ship_pro"></select><br>
  Address Line 1: <input type="text" name="line1"><br>
  Address Line 2: <input type="text" name="line2"><br>
  <span id="addr_3" style="visibility:hidden;">Address Line 3: <input type="text" name="line3"></span><br>
  </span>

  <input type="submit" Value="test">
</form>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.