Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-18-2008, 04:35 AM   PM User | #1
technopsych
New to the CF scene

 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
technopsych is an unknown quantity at this point
Javascript array - almost working

This is my first post to any coding forum - I have read the stickies - I will do my best. (I am not a programmer - late night hack really ). I have been working on an interesting run of code that will help me do health care documentation.

I have pulled just a piece of the page's code and pasted it below. As you can see the array is meant to build a list of medications and then dislpay them in a new window. It works... sort of... by clicking the selection boxes from left to right I can build a sentence for a medication prescription, ending it with a carriage return so that it builds a list on the new page.

However, if I add a second medication, I can't add the same item I added before. So, if I clicked "continue" in the selection box under "Action" the first time, I can click it again, but it won't enter the item into the textarea. The same is true of the other items in the other selection boxes - once an item is entered, it can't be entered a second time without a clearing click. My work around is to click on a blank area of the selection box and then re-click the "continue" - then it works.

I'm sure there is something easy that can be done - I just have no clue. I have searched and tinkered for hours. Any help would be greatly appreciated.

Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>MEDICATION</title>

<script language="JavaScript" type="text/javascript">
function display() {
DispWin = window.open('','NewWin', 'location=yes,menubar=no,scrollbars=no,toolbar=no,status=yes,resizable=yes,left=0px,top=236px,width=666,height=146')
message = "<b>Medications:</b>"
message += "<br><b></b>" + document.form5.medtxtarea.value;
DispWin.document.write(message);
DispWin.document.close();
}
</script>



<SCRIPT LANGUAGE="JavaScript">
<!--

var arrItems1 = new Array();
var arrItemsGrp1 = new Array();

arrItems1[0] = "25 MG";
arrItemsGrp1[0] = 1;
arrItems1[1] = "50 MG";
arrItemsGrp1[1] = 1;
arrItems1[2] = "75 MG";
arrItemsGrp1[2] = 1;
arrItems1[3] = "100 MG";
arrItemsGrp1[3] = 1;
arrItems1[4] = "125 MG";
arrItemsGrp1[4] = 1;
arrItems1[5] = "150 MG";
arrItemsGrp1[5] = 1;
arrItems1[6] = "175 MG";
arrItemsGrp1[6] = 1;
arrItems1[7] = "200 MG";
arrItemsGrp1[7] = 1;
arrItems1[8] = "225 MG";
arrItemsGrp1[8] = 1;
arrItems1[9] = "250 MG";
arrItemsGrp1[9] = 1;
arrItems1[10] = "275 MG";
arrItemsGrp1[10] = 1;
arrItems1[11] = "300 MG";
arrItemsGrp1[11] = 1;

arrItems1[20] = "100 MG";
arrItemsGrp1[20] = 2;
arrItems1[21] = "150 MG";
arrItemsGrp1[21] = 2;
arrItems1[22] = "200 MG";
arrItemsGrp1[22] = 2;
arrItems1[23] = "300 MG";
arrItemsGrp1[23] = 2;
arrItems1[23] = "450 MG";
arrItemsGrp1[23] = 2;

arrItems1[30] = "100 MG";
arrItemsGrp1[30] = 3;
arrItems1[31] = "150 MG";
arrItemsGrp1[31] = 3;
arrItems1[32] = "200 MG";
arrItemsGrp1[32] = 3;
arrItems1[33] = "300 MG";
arrItemsGrp1[33] = 3;
arrItems1[34] = "450 MG";
arrItemsGrp1[34] = 3;

arrItems1[40] = "10 MG";
arrItemsGrp1[40] = 4;
arrItems1[41] = "20 MG";
arrItemsGrp1[41] = 4;
arrItems1[42] = "30 MG";
arrItemsGrp1[42] = 4;
arrItems1[43] = "40 MG";
arrItemsGrp1[43] = 4;
arrItems1[44] = "50 MG";
arrItemsGrp1[44] = 4;
arrItems1[45] = "60 MG";
arrItemsGrp1[45] = 4;
arrItems1[46] = "70 MG";
arrItemsGrp1[46] = 4;
arrItems1[47] = "80 MG";
arrItemsGrp1[47] = 4;

arrItems1[50] = "50 MG";
arrItemsGrp1[50] = 5;
arrItems1[51] = "100 MG";
arrItemsGrp1[51] = 5;
arrItems1[52] = "150 MG";
arrItemsGrp1[52] = 5;
arrItems1[53] = "200 MG";
arrItemsGrp1[53] = 5;
arrItems1[54] = "250 MG";
arrItemsGrp1[54] = 5;
arrItems1[55] = "300 MG";
arrItemsGrp1[55] = 5;

arrItems1[60] = "50 MG";
arrItemsGrp1[60] = 6;
arrItems1[61] = "100 MG";
arrItemsGrp1[61] = 6;
arrItems1[62] = "150 MG";
arrItemsGrp1[62] = 6;
arrItems1[63] = "200 MG";
arrItemsGrp1[63] = 6;
arrItems1[64] = "250 MG";
arrItemsGrp1[64] = 6;
arrItems1[65] = "300 MG";
arrItemsGrp1[65] = 6;

arrItems1[70] = "50 MG";
arrItemsGrp1[70] = 7;
arrItems1[71] = "100 MG";
arrItemsGrp1[71] = 7;
arrItems1[72] = "150 MG";
arrItemsGrp1[72] = 7;
arrItems1[73] = "200 MG";
arrItemsGrp1[73] = 7;
arrItems1[74] = "250 MG";
arrItemsGrp1[74] = 7;
arrItems1[75] = "300 MG";
arrItemsGrp1[75] = 7;

arrItems1[80] = "20 MG";
arrItemsGrp1[60] = 8;
arrItems1[81] = "30 MG";
arrItemsGrp1[81] = 8;
arrItems1[82] = "40 MG";
arrItemsGrp1[82] = 8;
arrItems1[83] = "50 MG";
arrItemsGrp1[83] = 8;
arrItems1[84] = "60 MG";
arrItemsGrp1[84] = 8;
arrItems1[85] = "70 MG";
arrItemsGrp1[85] = 8;
arrItems1[86] = "80 MG";
arrItemsGrp1[86] = 8;

arrItems1[90] = "5 MG";
arrItemsGrp1[90] = 9;
arrItems1[91] = "10 MG";
arrItemsGrp1[91] = 9;
arrItems1[92] = "20 MG";
arrItemsGrp1[92] = 9;
arrItems1[93] = "30 MG";
arrItemsGrp1[93] = 9;
arrItems1[94] = "40 MG";
arrItemsGrp1[94] = 9;

arrItems1[100] = "10 MG";
arrItemsGrp1[100] = 10;
arrItems1[101] = "20 MG";
arrItemsGrp1[101] = 10;
arrItems1[102] = "30 MG";
arrItemsGrp1[102] = 10;
arrItems1[103] = "40 MG";
arrItemsGrp1[103] = 10;
arrItems1[104] = "50 MG";
arrItemsGrp1[104] = 10;
arrItems1[105] = "60 MG";
arrItemsGrp1[105] = 10;
arrItems1[106] = "70 MG";
arrItemsGrp1[106] = 10;
arrItems1[107] = "80 MG";
arrItemsGrp1[107] = 10;




function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
  var myEle ;
  var x ;
  // Empty the second drop down box of any choices
  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  if (control.name == "firstChoice") {
    // Empty the third drop down box of any choices
    for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
 }
  // ADD Default Choice - in case there are no values
  myEle = document.createElement("option") ;
  myEle.value = 0 ;
  myEle.text = "[SELECT]" ;
  // controlToPopulate.add(myEle) ;
  controlToPopulate.appendChild(myEle)
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ ) {
    if ( GroupArray[x] == control.value ) {
      myEle = document.createElement("option") ;
      //myEle.value = x ;
      myEle.setAttribute('value',x);
      // myEle.text = ItemArray[x] ;
      var txt = document.createTextNode(ItemArray[x]);
      myEle.appendChild(txt)
      // controlToPopulate.add(myEle) ;
      controlToPopulate.appendChild(myEle)
    }
  }
}

function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
  var myEle ;
  var x ;
  // Empty the second drop down box of any choices
  for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  if (control.name == "firstChoice") {
  }
  // ADD Default Choice - in case there are no values
  myEle=document.createElement("option");
  theText=document.createTextNode("[SELECT]");
  myEle.appendChild(theText);
  myEle.setAttribute("value","0");
  controlToPopulate.appendChild(myEle);
  // Now loop through the array of individual items
  // Any containing the same child id are added to
  // the second dropdown box
  for ( x = 0 ; x < ItemArray.length  ; x++ ) {
    if ( GroupArray[x] == control.value ) {
      myEle = document.createElement("option") ;
      //myEle.value = x ;
      myEle.setAttribute("value",x);
      // myEle.text = ItemArray[x] ;
      var txt = document.createTextNode(ItemArray[x]);
      myEle.appendChild(txt)
      // controlToPopulate.add(myEle) ;
      controlToPopulate.appendChild(myEle)
    }
  }
}

//--></SCRIPT>

</head>

<body>

<FORM NAME="form5" style="width: 750" method="get" onsubmit="return false">
<b>MEDICATION:</b>

<table border="1" id="table6" cellspacing="0" width="742" cellpadding="2">
	<tr>
		<td width="104">
		<b>Action:</b></td>
		<td width="243"><b>Medication:</b></td>
		<td width="96"><b>Dose:</b></td>
		<td width="66"><b>Tabs:</b></td>
		<td width="55"><b>Route:</b></td>
		<td width="75"><b>Frequency:</b></td>
		<td width="59"><b>PRN:</b></td>
	</tr>
	<tr>
		<td width="104">
		<select size="1" name="A1" Style="width: 99; height:22"
		onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">	
		<option></option>
		<option value="Continue">Continue</option>
		<option value="Start">Start</option>
		<option value="Increase">Increase</option>
		<option value="Decrease">Decrease</option>
		<option value="Discontinue">Discontinue</option>
		</select></td>

		<td width="243">
		<select Style="width: 236; height:22" id="firstChoice" name="M1" 
		onchange="selectChange(this, form.secondChoice, arrItems1, arrItemsGrp1); 
		if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
        <option value="0"></option>
        <option value="1">Amitriptyline (Elavil)</option>
        <option value="2">Bupropion (Wellbutrin SR)</option>
        <option value="3">Bupropion (Wellbutrin XL)</option>
        <option value="4">Citalopram (Celexa)</option>
        <option value="5">Clomipramine (Anafranil)</option>
        <option value="6">Desipramine (Norpramin)</option>
        <option value="7">Doxepin (Sinequan)</option>
        <option value="8">Duloxetine (Cymbalta)</option>
        <option value="9">Escitalopram (Lexapro)</option>
        <option value="10">Fluoxetine (Prozac)</option>
		</select>
</td>
		<td width="96">
      	<select Style="width: 90; height:22" id="secondChoice" name="D1"
		onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
		</select></td>
		<td width="66">
      	<select size="1" name="T1" Style="width: 60; height:22"
      	onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
		<option> </option>
		<option value="1/4">1/4</option>
		<option value="1/2">1/2</option>
		<option value="1">1</option>
		<option value="1 1/2">1 1/2</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
		<option value="6">6</option>
		<option value="7">7</option>
		<option value="8">8</option>
		</select></td>
		<td width="55">
		<select size="1" name="R1" Style="width: 50; height:22"
		onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
		<option></option>
		<option value="PO">PO</option>
		<option value="IM">IM</option>
		</select></td>
		<td width="75"><select size="1" name="F1" Style="width: 70; height:22"
		onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
		<option></option>
		<option value="QD">QD</option>
		<option value="QAM">QAM</option>
		<option value="QHS">QHS</option>
		<option value="BID">BID</option>
		<option value="TID">TID</option>
		<option value="QID">QID</option>
		<option value="Q2 hr">Q2 hr</option>
		<option value="Q4 hr">Q4 hr</option>
		<option value="Q6 hr">Q6 hr</option>
		<option value="Q8 hr">Q8 hr</option>
		<option value="Q12 hr">Q12 hr</option>
		<option value="Q1 wk">Q1 wk</option>
		<option value="Q2 wk">Q2 wk</option>
		<option value="Q3 wk">Q3 wk</option>
		<option value="Q4 wk">Q4 wk</option>
		</select></td>
		<td width="59" align="center">
		<p align="left">
		<select size="1" name="P1" Style="width: 55; height:22"
		onchange="
      	if(this.value == '') return false;
      	if(this.form.medtxtarea.value.indexOf('*') > -1)
      	this.form.medtxtarea.value = '';
      	this.form.medtxtarea.value += '  ' + this.options[this.selectedIndex].text;">
		<option></option>
		<option value="&lt;br&gt;">&lt;br&gt;</option>		
		<option value="PRN">PRN&lt;br&gt;</option>
		</select></td>
	</tr>

	</table>
<p>

<textarea name="medtxtarea" rows="6" cols="90"></textarea>

 </p>

<p>

<input value="Display" onclick="display();" type="button"></p>

</form> 
</html>
technopsych is offline   Reply With Quote
Old 08-18-2008, 02:46 PM   PM User | #2
mic2100
Regular Coder

 
mic2100's Avatar
 
Join Date: Feb 2006
Location: Scunthorpe
Posts: 562
Thanks: 15
Thanked 28 Times in 27 Posts
mic2100 is on a distinguished road
i would reset the dropdown values back to their default value, this would then allow you to reselect the same value again.
mic2100 is offline   Reply With Quote
Old 08-18-2008, 03:17 PM   PM User | #3
technopsych
New to the CF scene

 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
technopsych is an unknown quantity at this point
That sounds encouraging... any ideas on the code? I am still such a noobie - I need simple directions in most cases.

Would I have to reset the values by some kind of button press onclick, or could the values reset automatically after a selection?

Thanks for the reply - I am hopeful that there is a solution.
technopsych is offline   Reply With Quote
Old 08-18-2008, 09:24 PM   PM User | #4
technopsych
New to the CF scene

 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
technopsych is an unknown quantity at this point
mic2100's comment about reset got me searching on another set of words... I came across a piece of code that did the trick. A little onchange command that resets the selection box back to default. Thanks for the help

Code:
this.form.currentSel.value=this.options[this.selectedIndex].value;this.selectedIndex=0
technopsych is offline   Reply With Quote
Reply

Bookmarks

Tags
array, drop-down box, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:09 AM.


Advertisement
Log in to turn off these ads.