I found this code and have implemented it with limited success. It's the Java bit that's baffling me. The goal is to produce a dropdown box for the first instance of the shiptogroup (there are five total) and a blank cell for all other instances. When a selection is made from the dropdown box, I'd like all the other cells in that group to populate with that selection. So far, only the first cell is populated.

if($shiptogroup=="group4"){
	if($grp4==0){
	$displayblock .= "<select size=\"1\" name=\"shipto4\" onchange=\"document.getElementById ('grp4name').firstChild.data = this.options [this.selectedIndex].text\">
		<option>- Select -</option>
		<option>Arlington S</option>
		<option>Mansfield</option>
		</select>";
		$grp4=1;
	}else{
	$displayblock .= "<p id=\"grp4name\">&nbsp;</p>";
	}
	}

Many thanks for your help,
Reta

Recommended Answers

All 9 Replies

This looks like PHP code to me

I think the same. Variables in PHP starts with "$", and ".=" is a way to concatenate string in PHP. I'm not going to give more example because there are tons of example on the Internet. Here is one example. The javascript code for the page is here.

Correct, it is mostly PHP, with just a sprinkle of javascript in there. It's the onchange code that attempts to do what I'd like it to do, I think.

"<select size=\"1\" name=\"shipto4\" onchange=\"document.getElementById ('grp4name').firstChild.data = this.options [this.selectedIndex].text\">

Let me be even clearer. The code above produces part of a table, the Ship To column of the table. While looping through the shiptogroups, upon the first instance of shipto1 (or shipto2, shipto3, etc.) a dropdown box is inserted showing the different locations within that shiptogroup. (Group 4 is the example code given.) Subsequent instances of the shipto1 group would only get a blank cell, no dropdown box, no text box, just an empty cell.

[IMG]https://picasaweb.google.com/retareed/Help?authkey=Gv1sRgCOGxtMD51uaRHA#5576602812621631330[/IMG]

Currently when a selection is made from the dropdown, only the first empty cell of the same shiptogroup is populated with the selection. I just want the selection to display in all cells of the same shiptogroup. This info is not getting saved/uploaded/sent to a database anywhere, just displayed.

Hmm... I start to think that it is weird to do the way you do (from the code snippet you showed above) even with your explanation...

OK, how many combo boxes (select boxes) in the view? I thought you have 2 combo boxes which are A and B. Then when you change the combo box A, combo box B options are changed according to the selected item of combo box A. Is that correct?

No. The dropdown boxes do not affect the other dropdowns. There would be a total of five dropdown boxes, one for each shipto group. When a selection is made from the dropdown box, I only want the blank cells related to that same shiptogroup to fill in with the selection made. Currently only the first blank cell is populated with the selection made, not all blank cells related to the shiptogroup.

Oh I see. Hmm... I am not sure about how you construct your PHP code. Here is a sample for pure JavaScript with HTML. May give you an idea how to construct your JavaScript in your PHP code.

<html>
<head>
<script type="text/javascript">
function changeRelatedDiv(selID, divID) {
  var selectEl = document.getElementById(selID)
  var divEl = document.getElementById(divID)
  if (selectEl && divEl) {  // if both elements exist, continue
    divEl.innerHTML = selectEl[selectEl.selectedIndex].value
  }
}
</script>
</head>

<body>
  <table>
  <tr><td>

  <select id="grp1" name="grp1" onchange="changeRelatedDiv('grp1', 'grp1div')">
  <option value="Group 1 Value 1">Value 1</option>
  <option value="Group 1 Value 2">Value 2</option>
  <option value="Group 1 Value 3">Value 3</option>
  <option value="Group 1 Value 4">Value 4</option>
  </select>

  </td><td>

  <select id="grp2" name="grp2" onchange="changeRelatedDiv('grp2', 'grp2div')">
  <option value="Group 2 Value 1">Value 1</option>
  <option value="Group 2 Value 2">Value 2</option>
  <option value="Group 2 Value 3">Value 3</option>
  <option value="Group 2 Value 4">Value 4</option>
  </select>

  </td><td>

  <select id="grp3" name="grp3" onchange="changeRelatedDiv('grp3', 'grp3div')">
  <option value="Group 3 Value 1">Value 1</option>
  <option value="Group 3 Value 2">Value 2</option>
  <option value="Group 3 Value 3">Value 3</option>
  <option value="Group 3 Value 4">Value 4</option>
  </select>

  </td><td>

  <select id="grp4" name="grp4" onchange="changeRelatedDiv('grp4', 'grp4div')">
  <option value="Group 4 Value 1">Value 1</option>
  <option value="Group 4 Value 2">Value 2</option>
  <option value="Group 4 Value 3">Value 3</option>
  <option value="Group 4 Value 4">Value 4</option>
  </select>

  </td></tr>

  <tr><td>
  <div id="grp1div" name="grp1div" style="width:150px"></div>
  </td><td>
  <div id="grp2div" name="grp2div" style="width:150px"></div>
  </td><td>
  <div id="grp3div" name="grp3div" style="width:150px"></div>
  </td><td>
  <div id="grp4div" name="grp4div" style="width:150px"></div>
  </td></tr>
  </table>
</body>
</html>

Thanks very much. This still only accomplishes what I already had working - Only the first blank cell is populated with the selection. I think I'll approach this from a different route. Thank you for your efforts!

Sorry for not being helpful. I am not sure what's your current code for the portion. I mean the whole part of constructing the script... If it is being populated only your first selection, it means that others do not get the right 'target' element to be written on. My example does that; however, you must specify a correct set of argument passing to the function. If you don't, it won't work properly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.