473,624 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to get 2 Javascripts working together

1 New Member
So I am not great at Javascript, but i have 2 scripts that i want to work with each other. When i use one by itself, they each work fine, but when i add them together it does not work.

I have a user form with a bunch of fields on it. If they choose an option on the drop down menu, some fields either show or disappear. Those fields have an "On Change" event that subtracts one field form another and gives us a total.
////////////////////////////////////// Drop Down Menu /////
Expand|Select|Wrap|Line Numbers
  1. rel sets to show the <tr>
  2. <select name="checkout_by" class="textLeft" id="checkout_by" value="<?php if($cont == 'no') { echo $checkout_by; } ?>" > <option value="serial" selected rel="show">Item Series / Serial Number</option>
  3. <option value="isbn" rel="none">Barcode / ISBN Number</option>
//////////////////////////////////// Fields used to subtract

Expand|Select|Wrap|Line Numbers
  1. <input name="serial_start" onChange="updatesum()" type="text" class="textLeft" id="serial_start" value="<?php if($cont == 'no') { echo $serial_start; } ?>" size="15">

Expand|Select|Wrap|Line Numbers
  1. <input name="serial_end" onChange="updatesum()" type="text" class="textLeft" id="serial_end" value="<?php if($cont == 'no') { echo $serial_end; } ?>" size="15">

//////////////////////////////////// Field used to add the total up from above

Expand|Select|Wrap|Line Numbers
  1. <input name="org_quantity" type="text" id="org_quantity" value="<?php if($cont == 'no') { echo $orig_quantity; } ?>" size="10">
  2.  


///////////////////////////////////////Update total
Expand|Select|Wrap|Line Numbers
  1. script
  2. <script type="text/javascript">
  3. function updatesum() {
  4. document.form1.org_quantity.value = (document.form1.serial_end.value -0) - (document.form1.serial_start.value -0);
  5. }
  6. </script>

//////////////////////////////////// Hide Filed Script
Expand|Select|Wrap|Line Numbers
  1. var containerTag = 'TR';
  2.  
  3. var compatible = (
  4. document.getElementById && document.getElementsByTagName && document.createElement
  5. &&
  6. !(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1)
  7. );
  8.  
  9. if (compatible)
  10. {
  11. document.write('<style>.accessibility{display: none}</style>');
  12. var waitingRoom = document.createElement('div');
  13. }
  14.  
  15. var hiddenFormFieldsPointers = new Object();
  16.  
  17. function prepareForm()
  18. {
  19. if (!compatible) return;
  20. var marker = document.createElement(containerTag);
  21. marker.style.display = 'none';
  22.  
  23. var x = document.getElementsByTagName('select');
  24. for (var i=0;i<x.length;i++)
  25. addEvent(x[i],'change',showHideFields)
  26.  
  27. var x = document.getElementsByTagName(containerTag);
  28. var hiddenFields = new Array;
  29. for (var i=0;i<x.length;i++)
  30. {
  31. if (x[i].getAttribute('rel'))
  32. {
  33. var y = getAllFormFields(x[i]);
  34. x[i].nestedRels = new Array();
  35. for (var j=0;j<y.length;j++)
  36. {
  37. var rel = y[j].getAttribute('rel');
  38. if (!rel || rel == 'none') continue;
  39. x[i].nestedRels.push(rel);
  40. }
  41. if (!x[i].nestedRels.length) x[i].nestedRels = null;
  42. hiddenFields.push(x[i]);
  43. }
  44. }
  45.  
  46. while (hiddenFields.length)
  47. {
  48. var rel = hiddenFields[0].getAttribute('rel');
  49. if (!hiddenFormFieldsPointers[rel])
  50. hiddenFormFieldsPointers[rel] = new Array();
  51. var relIndex = hiddenFormFieldsPointers[rel].length;
  52. hiddenFormFieldsPointers[rel][relIndex] = hiddenFields[0];
  53. var newMarker = marker.cloneNode(true);
  54. newMarker.id = rel + relIndex;
  55. hiddenFields[0].parentNode.replaceChild(newMarker,hiddenFields[0]);
  56. waitingRoom.appendChild(hiddenFields.shift());
  57. }
  58.  
  59. setDefaults();
  60. addEvent(document,'click',showHideFields);
  61. }
  62.  
  63. function setDefaults()
  64. {
  65. var y = document.getElementsByTagName('input');
  66. for (var i=0;i<y.length;i++)
  67. {
  68. if (y[i].checked && y[i].getAttribute('rel'))
  69. intoMainForm(y[i].getAttribute('rel'))
  70. }
  71.  
  72. var z = document.getElementsByTagName('select');
  73. for (var i=0;i<z.length;i++)
  74. {
  75. if (z[i].options[z[i].selectedIndex].getAttribute('rel'))
  76. intoMainForm(z[i].options[z[i].selectedIndex].getAttribute('rel'))
  77. }
  78.  
  79. }
  80.  
  81. function showHideFields(e)
  82. {
  83. if (!e) var e = window.event;
  84. var tg = e.target || e.srcElement;
  85.  
  86. if (tg.nodeName == 'LABEL')
  87. {
  88. var relatedFieldName = tg.getAttribute('for') || tg.getAttribute('htmlFor');
  89. tg = document.getElementById(relatedFieldName);
  90. }
  91.  
  92. if (
  93. !(tg.nodeName == 'SELECT' && e.type == 'change')
  94. &&
  95. !(tg.nodeName == 'INPUT' && tg.getAttribute('rel'))
  96. ) return;
  97.  
  98. var fieldsToBeInserted = tg.getAttribute('rel');
  99.  
  100. if (tg.type == 'checkbox')
  101. {
  102. if (tg.checked)
  103. intoMainForm(fieldsToBeInserted);
  104. else
  105. intoWaitingRoom(fieldsToBeInserted);
  106. }
  107. else if (tg.type == 'radio')
  108. {
  109. removeOthers(tg.form[tg.name],fieldsToBeInserted)
  110. intoMainForm(fieldsToBeInserted);
  111. }
  112. else if (tg.type == 'select-one')
  113. {
  114. fieldsToBeInserted = tg.options[tg.selectedIndex].getAttribute('rel');
  115. removeOthers(tg.options,fieldsToBeInserted);
  116. intoMainForm(fieldsToBeInserted);
  117. }
  118. }
  119.  
  120. function removeOthers(others,fieldsToBeInserted)
  121. {
  122. for (var i=0;i<others.length;i++)
  123. {
  124. var show = others[i].getAttribute('rel');
  125. if (show == fieldsToBeInserted) continue;
  126. intoWaitingRoom(show);
  127. }
  128. }
  129.  
  130. function intoWaitingRoom(relation)
  131. {
  132. if (relation == 'none') return;
  133. var Elements = hiddenFormFieldsPointers[relation];
  134. for (var i=0;i<Elements.length;i++)
  135. {
  136. waitingRoom.appendChild(Elements[i]);
  137. if (Elements[i].nestedRels)
  138. for (var j=0;j<Elements[i].nestedRels.length;j++)
  139. intoWaitingRoom(Elements[i].nestedRels[j]);
  140. }
  141. }
  142.  
  143. function intoMainForm(relation)
  144. {
  145. if (relation == 'none') return;
  146. var Elements = hiddenFormFieldsPointers[relation];
  147. for (var i=0;i<Elements.length;i++)
  148. {
  149. var insertPoint = document.getElementById(relation+i);
  150. insertPoint.parentNode.insertBefore(Elements[i],insertPoint);
  151. if (Elements[i].nestedRels)
  152. {
  153. var fields = getAllFormFields(Elements[i]);
  154. for (var j=0;j<fields.length;j++)
  155. {
  156. if (!fields[j].getAttribute('rel')) continue;
  157. if (fields[j].checked || fields[j].selected)
  158. intoMainForm(fields[j].getAttribute('rel'));
  159. }
  160. }
  161. }
  162. }
  163.  
  164. function getAllFormFields(node)
  165. {
  166. var allFormFields = new Array;
  167. var x = node.getElementsByTagName('input');
  168. for (var i=0;i<x.length;i++)
  169. allFormFields.push(x[i]);
  170. var y = node.getElementsByTagName('option');
  171. for (var i=0;i<y.length;i++)
  172. allFormFields.push(y[i]);
  173. return allFormFields;
  174. }
  175.  
  176. /** ULTRA-SIMPLE EVENT ADDING **/
  177.  
  178. function addEvent(obj,type,fn)
  179. {
  180. if (obj.addEventListener)
  181. obj.addEventListener(type,fn,false);
  182. else if (obj.attachEvent)
  183. obj.attachEvent("on"+type,fn);
  184. }
  185.  
  186. addEvent(window,"load",prepareForm);
  187.  
  188.  
  189. /** PUSH AND SHIFT FOR IE5 **/
  190.  
  191. function Array_push() {
  192. var A_p = 0
  193. for (A_p = 0; A_p < arguments.length; A_p++) {
  194. this[this.length] = arguments[A_p]
  195. }
  196. return this.length
  197. }
  198.  
  199. if (typeof Array.prototype.push == "undefined") {
  200. Array.prototype.push = Array_push
  201. }
  202.  
  203. function Array_shift() {
  204. var A_s = 0
  205. var response = this[0]
  206. for (A_s = 0; A_s < this.length-1; A_s++) {
  207. this[A_s] = this[A_s + 1]
  208. }
  209. this.length--
  210. return response
  211. }
  212.  
  213. if (typeof Array.prototype.shift == "undefined") {
  214. Array.prototype.shift = Array_shift
  215. }
Aug 3 '10 #1
1 1482
dlite922
1,584 Recognized Expert Top Contributor
Use firefox. Open Tools-> Error Console.

Do you see any errors for your site?

(Hit the red circle (delete) and access your page again if there are too many errors)

What is the first error you see?

Dan
Aug 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1839
by: mackenzie | last post by:
Hi, I found a great js calendar pop-up that i want to use on the same page where i'm already using a .vbs for client- side script. I can use either one individually w/o problems but, when I try to use them both, it appears that .NET is treating the js as vbs. I get 2 dominating errors that I supect are coming from the js file: 1.Expected and of statement and 2.Cannot use parentheses when calling a Sub. Is what I'm trying to do...
0
1136
by: Sokolov Yura | last post by:
Django Model is wonderfull. But SQLObject more flexible (and powerfull, as i think, and has already more db interfaces). But Django Model is tied with Django, and using Django with another OO mapping is not comfortable. Why do not working together? I can't understand. If you (Django and SQLObject) would, you'll beat everyone else in efficiency (i mean ROR and maybe some Python's frameworks). It is for all of Open Source. There a lot of...
13
1301
by: David L Wright II | last post by:
Does anyone know when building a msi file under VB.Net 2003, it would try to install something from the VS 2005 Beta 1? I have both products installed. Thanks,
2
1157
by: phil cunningham | last post by:
I am using Access to run a database within the company and also have a website that makes some of the information available to the general public And so far everything is working very well q. is there any problem using Access to do all our internal work while the DB is exposed to the web q. if I move to SQL server can I still use all the features of Access (VBA reporting etc) for our internal work
0
1080
by: Rod | last post by:
Well, I've taken the plunge and gotten myself my first domain. (I've worked on other peoples and of course at work, but never done my own domain.) With this new project my family and I will likely work on it together. And we'll be using FrontPage 2003. I would also like to use Visual Studio 2005 for those portions when appropriate (such as a members' only area), so I would like to know how to make FP 2003 and Visual Studio 2005 work...
4
10415
by: geshan | last post by:
In php5 I am not able to use include funciton and header("location:""" together please help.
2
2379
by: buddyr | last post by:
Hello, I am having trouble with two combo boxes working together. two tables table1 table2 table1 fields -number and name table 2 fields -code and number data in table one field number 1,2,3 data in table one field name Tom, Bob, Jim data in table two field code 11,22,33,44,55,66, data in table two field number 1,2,3,1,2,3
4
3078
by: MimiMi | last post by:
I'm trying to put together a http response header. It seems to work, except for that I don't get the data string added correctly! I wouldn't be surprised if my problems have something to do with my still existing confusion over arrays and pointers in C since I'm still a newbie, but anyhow, here's the code: #include <time.h> #include <stdio.h> #define WEBBUF_SIZE 32768
0
1953
by: VicJ | last post by:
I'm trying to make a control on which the user can freely drag an image with the mouse and zoom and rotate it with the mouse wheel. I'd like to do this as far as possible using graphics transforms. At the moment, I have the code below in the Paint event handler of a Windows Form. The variables PanOrigin (Point), ZoomFactor (Single, starting value 1.0) and RotateDegrees (Integer) are controlled by mouse actions; I trust their meanings are...
3
1920
by: SavRak | last post by:
Hi, I seem to be having an issue linking my XML document and XML Schema together. Both are not working, and do not seem to be validating when using: http://tools.decisionsoft.com/schemaValidate/ Im not sure if what I have will work, or does work, as I can still output the XML via an XSLT fine :S Ive attached my XML page and XML Schema, if someone could have a look I would be very grateful! Thanks,
0
8175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.