Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox should go with checkbox value in textarea 1

Status
Not open for further replies.

kcassell

IS-IT--Management
Aug 15, 2000
1
US
Hello,<br>&nbsp;<br>I have a problem by assigning a value of Quantity in a textarea.&nbsp;&nbsp;When a user clicks a checkbox, the value of checkbox and quantity should appear together in textarea.&nbsp;&nbsp;I get undefined because it seems not function properly.&nbsp;&nbsp;Thank you very much for your time and help!<br>&nbsp;<br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--<br>function setField(theForm)<br>{<br>&nbsp;theForm.quantity.value = 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;theForm.order.value = &quot;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;var val = &quot;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;for (var i=0; i&lt;theForm.equipment.length; i++) ¦¦ (var i=0; i&lt;theForm.quantity.length; i++)<br>&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((theForm.equipment<i>.name.indexOf('equipment') &gt; -1)) ¦¦ ((theForm.quantity<i>.name.indexOf('quantity') &gt; -1))<br>&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (theForm.equipment<i>.checked) ¦¦ theForm.quantity['quantity' + i].value<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theForm.order.value += theForm.equipment<i>.value + &quot; - &quot; + theForm.quantity<i>.value + &quot;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>&nbsp;<br>file://--&gt;<br>&lt;/script&gt;<br>&nbsp;<br>&lt;form name=&quot;order&quot;&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment&quot; value=&quot;Printer&quot; onClick=&quot;setField(this.form)&quot;&gt;<br>&lt;input type=&quot;text&quot; name=&quot;quantity&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment&quot; value=&quot;Mouse&quot; onClick=&quot;setField(this.form)&quot;&gt;<br>&lt;input type=&quot;text&quot; name=&quot;quantity&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment&quot; value=&quot;Keyboard&quot; onClick=&quot;setField(this.form)&quot;&gt;<br>&lt;input type=&quot;text&quot; name=&quot;quantity&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;textarea onChange=&quot;setField(this.form)&quot; name=order value=&quot;?&quot; rows=5&gt;&lt;/textarea&gt;<br>&lt;br&gt;<br>&lt;/form&gt;<br>&nbsp;
 
You can only give a group of radio buttons the same name. your problem is that you are trying to access the values of three different textboxes that each have the same name. try out this code.&nbsp;&nbsp;when the box is checked, the quantity appears in the text area along with the item name, as long as the quantity of the item is greater than 0.<br><br><br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--<br>var iNumBoxes = 3;<br>function setField(theForm) {<br>&nbsp;&nbsp;&nbsp;theForm.order.value = &quot;&quot;;<br>&nbsp;&nbsp;&nbsp;var val = &quot;&quot;;<br>&nbsp;&nbsp;&nbsp;for(var i = 0; i &lt; iNumBoxes; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (theForm['equipment' + i].checked && theForm['quantity' + i].value &gt; 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theForm.order.value += theForm['equipment' + i].value + &quot; - &quot; + theForm['quantity' + i].value + &quot;\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;}<br>}<br>file://--&gt;<br>&lt;/script&gt;<br><br>&lt;form name=&quot;order&quot;&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment0&quot; value=&quot;Printer&quot; onClick=&quot;setField(this.form)&quot;&gt;Printer<br>&lt;input type=&quot;text&quot; name=&quot;quantity0&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment1&quot; value=&quot;Mouse&quot; onClick=&quot;setField(this.form)&quot;&gt;Mouse<br>&lt;input type=&quot;text&quot; name=&quot;quantity1&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;input type=&quot;checkbox&quot; name=&quot;equipment2&quot; value=&quot;Keyboard&quot; onClick=&quot;setField(this.form)&quot;&gt;Keyboard<br>&lt;input type=&quot;text&quot; name=&quot;quantity2&quot; value=&quot;1&quot; size=2 onChange=&quot;setField(this.form)&quot;&gt;<br>&lt;br&gt;<br>&lt;textarea onChange=&quot;setField(this.form)&quot; name=order value=&quot;?&quot; rows=5&gt;&lt;/textarea&gt;<br>&lt;br&gt;<br>&lt;/form&gt;  <br><br> <p>ray<br><a href=mailto:rheindl@bju.edu>rheindl@bju.edu</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top