Help needed to get information across forms with javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DDragon
    New Member
    • Aug 2007
    • 15

    Help needed to get information across forms with javascript

    ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other form to it... ill post the code for you to look at and try to explaine in detail what im trying to do.

    here is the code (HTML and Javascript so you get the whole picture):

    Javascript:
    Code:
    var gen, lights;
    
    var lammount;
    
    
    
    function validatetheform()
    	{
    		if (!document.frmTorder.txtBname.value)
    			{
    				alert("Please enter your buisness name.");
    				document.frmTorder.txtBname.focus();
    			}
    
    		else if(!document.frmTorder.txtBaddy.value)
    			{
    				alert("Please enter you Buisness address.");
    				document.frmTorder.txtBaddy.focus();
    			}
    
    		else if(!document.frmTorder.txtPcode.value)
    			{
    				alert("Plese enter your postcode");
    				document.frmTorder.txtPcode.focus();
    			}
    
    		else if(!document.frmTorder.txtState.value)
    			{
    				alert("Please enter you state.");
    				document.frmTorder.txtState.focus();
    			}
    
    		else if(!document.frmTorder.txtSite.value)
    			{
    				alert("Please enter the event address.");
    				document.frmTorder.txtSite.focus();
    			}
    
    		return true;
    	}
    
    
    function total_add()
    	{
    
    		var bubbleday, simday, slideday, bungiesday;
    		var bubble, sim, slide, bungies;
    		var bubblet, simt, slidet, bungiest;
    
    		var total;
    
    		// Setting the value for the days
    		bubbleday = document.frmTorder.txtBubbledays.value;
    		simday = document.frmTorder.txtSimdays.value;
    		slideday = document.frmTorder.txtSlidedays.value;
    		bungiesday = document.frmTorder.txtBungiedays.value;
    
    		// setting the value for the set price
    		bubble = document.frmTorder.txtBubbleprice.value;
    		sim = document.frmTorder.txtSimprice.value;
    		slide = document.frmTorder.txtSlideprice.value;
    		bungies = document.frmTorder.txtBungieprice.value;
    
    		// calculating the total of the individual rides
    		bungiest = bungies * bungiesday;
    		simt = sim * simday;
    		slidet = slide * slideday;
    		bubblet = bubble * bubbleday;
    
    		// setting the value total with the ammounts from the rides
    		total = bubblet + slidet + simt + bungiest;
    
    		document.frmTorder.txtTotalprice.value = total;
    
    	}
    
    
    
    function extras()
    
    	{
    		if (document.frmExtras.chkGen = selected)
    
    			{
    
    				gen = document.frmExtras.txtGenprice.value;
    
    			}
    
    
    
    		alert("Gen amount is: " + gen);
    	
    	}
    and the html (form 1):

    Code:
    <form name="frmTorder" method="post" onSubmit="validatetheform()" onReset="document.frmTorder.txtBname.focus()">
    				<font color="lightgreen"><strong>*</strong></font>Buisness Name: &nbsp;<input type="text" name="txtBname" size="20"><br />
    				<font color="lightgreen"><strong>*</strong></font>Address: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="txtBaddy" size="50"><br />
    				<font color="lightgreen"><strong>*</strong></font>Post Code: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="txtPcode" size="4"> <font color="lightgreen"><strong>*</strong></font>State: <input type="text" name="txtState" size="4"><br />
    
    				<br /><hr /><br />
    
    				<font color="lightgreen"><strong>*</strong></font>Address of event: &nbsp;&nbsp;<input type="text" name="txtSite" size="50"><br />
    						
    				<font color="lightgreen"><strong>*</strong></font>Start date: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="txtSdate" class="calendarSelectDate" size="10"/> <font color="lightgreen"><strong>*</strong></font>End date of event: <input type="text" name="txtEdate" size="10" class="calendarSelectDate"><br />
    				Street Referance: &nbsp;&nbsp;&nbsp;<input type="text" name="txtSref" size="50"><br />
    
    				<br /><hr /><br />
    
    				<center><table name="tblRides" border="0">
    					<tr>
    						<td>Rides</td>
    
    						<td><font color="lightgreen"><strong>*</strong></font>Required Days</td>
    
    						<td><center>Price</center></td>
    
    					</tr>
    
    					<tr>
    
    						<td>Trampoline Bungies</td>
    
    						<td><center><input type="text" name="txtBungiedays" size="2" onchange="total_add()"></center></td>
    
    						<td class="price"><center><input type="text" name="txtBungieprice" size="7" value="2000.00" disabled></center></td>
    
    					</tr>
    
    					<tr>
    
    						<td>Tarzan Jumping Castel</td>
    
    						<td><center><input type="text" name="txtBubbledays" size="2" onChange="total_add()"></center></td>
    
    						<td class="price"><center><input type="text" name="txtBubbleprice" size="7" value="1200.00" disabled></center></td>
    
    					</tr>
    
    					<tr>
    
    						<td>Voyager Simulator</td>
    
    						<td><center><input type="text" name="txtSimdays" size="2" onChange="total_add()"></center></td>
    
    						<td class="price"><center><input type="text" name="txtSimprice" size="7" value="1850.00" disabled></center></td>
    
    					</tr>
    
    					<tr>
    
    						<td>Giant Slide</td>
    
    						<td><center><input type="text" name="txtSlidedays" size="2" onChange="total_add()"></center></td>
    
    						<td class="price"><center><input type="text" name="txtSlideprice" size="7" value="1850.00" disabled></center></td>
    
    					</tr>
    
    					<tr>
    
    						<td>Food Van</td>
    
    						<td><center><input type="text" name="txtFvandays" size="2" onChange="total_add()"></center></td>
    
    						<td class="price"><center><input type="text" name="txtFvanprice" size="7" value="0.00" disabled></center></td>
    
    					</tr>
    
    					<tr>
    
    						<td></td>
    
    						<td>Total Amount Owing: $</td>
    
    						<td class="price"><input type="text" name="txtTotalprice" size="7" disabled></td>
    
    					</tr>
    				</table></center><br />
    
    				<center>Extra Details/Questions: <br /><textarea name="txtComments" rows="8" cols="40">Place any extra details or questions here.</textarea></center><br /><br />
    
    				<center><input type="submit" name="btnSubmit" value="Make Booking"> <input type="reset" name="btnReset" value="Reset the order"></center>
    			</form>
    (form 2):
    Code:
    <form name="frmExtras" method="post">
    					<li><input type="checkbox" name="chkGen"> Generator (Simulator Only).<input type="hidden" name=txtGenprice" value="1000" onchange="extras()"></li>
    					<li><input type="checkbox" name="chkLights"> Lights. <br /><input type="text" name="txtLammount" value="0" size="2" onchange=""> Ammount needed.<input type="hidden" name=txtLprice" value="1000"></li>
    				</form>
    Now what i need is to be able to get the values of 'frmExtras' into the box 'txtTotalprice' if the check box for chkGen is selected or an ammount from 'txtLammount' if it has a value in it.. ive been trying to nut it out and my own knowledge is just too limited i need help with it... any advice of how to go about it would be great.

    DD
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    changed thread title ... please be sure to use a proper thread title for your post ... read this section of the posting guidelines ...

    kind regards
    MOD

    Comment

    • DDragon
      New Member
      • Aug 2007
      • 15

      #3
      Help needed to get information across forms with javascript

      ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other form to it... ill post the code for you to look at and try to explaine in detail what im trying to do.

      here is the code (HTML and Javascript so you get the whole picture):

      Javascript:
      [code=javascript]
      var gen, lights;

      var lammount;



      function validatetheform ()
      {
      if (!document.frmT order.txtBname. value)
      {
      alert("Please enter your buisness name.");
      document.frmTor der.txtBname.fo cus();
      }

      else if(!document.fr mTorder.txtBadd y.value)
      {
      alert("Please enter you Buisness address.");
      document.frmTor der.txtBaddy.fo cus();
      }

      else if(!document.fr mTorder.txtPcod e.value)
      {
      alert("Plese enter your postcode");
      document.frmTor der.txtPcode.fo cus();
      }

      else if(!document.fr mTorder.txtStat e.value)
      {
      alert("Please enter you state.");
      document.frmTor der.txtState.fo cus();
      }

      else if(!document.fr mTorder.txtSite .value)
      {
      alert("Please enter the event address.");
      document.frmTor der.txtSite.foc us();
      }

      return true;
      }


      function total_add()
      {

      var bubbleday, simday, slideday, bungiesday;
      var bubble, sim, slide, bungies;
      var bubblet, simt, slidet, bungiest;

      var total;

      // Setting the value for the days
      bubbleday = document.frmTor der.txtBubbleda ys.value;
      simday = document.frmTor der.txtSimdays. value;
      slideday = document.frmTor der.txtSlideday s.value;
      bungiesday = document.frmTor der.txtBungieda ys.value;

      // setting the value for the set price
      bubble = document.frmTor der.txtBubblepr ice.value;
      sim = document.frmTor der.txtSimprice .value;
      slide = document.frmTor der.txtSlidepri ce.value;
      bungies = document.frmTor der.txtBungiepr ice.value;

      // calculating the total of the individual rides
      bungiest = bungies * bungiesday;
      simt = sim * simday;
      slidet = slide * slideday;
      bubblet = bubble * bubbleday;

      // setting the value total with the ammounts from the rides
      total = bubblet + slidet + simt + bungiest;

      document.frmTor der.txtTotalpri ce.value = total;

      }



      function extras()

      {
      if (document.frmEx tras.chkGen = selected)

      {

      gen = document.frmExt ras.txtGenprice .value;

      }



      alert("Gen amount is: " + gen);

      }
      [/code]

      and the html (form 1):

      [html]
      <form name="frmTorder " method="post" onSubmit="valid atetheform()" onReset="docume nt.frmTorder.tx tBname.focus()" >
      <font color="lightgre en"><strong>* </strong></font>Buisness Name: &nbsp;<input type="text" name="txtBname" size="20"><br />
      <font color="lightgre en"><strong>* </strong></font>Address: &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;<in put type="text" name="txtBaddy" size="50"><br />
      <font color="lightgre en"><strong>* </strong></font>Post Code: &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;<input type="text" name="txtPcode" size="4"> <font color="lightgre en"><strong>* </strong></font>State: <input type="text" name="txtState" size="4"><br />

      <br /><hr /><br />

      <font color="lightgre en"><strong>* </strong></font>Address of event: &nbsp;&nbsp;<in put type="text" name="txtSite" size="50"><br />

      <font color="lightgre en"><strong>* </strong></font>Start date: &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;<in put type="text" name="txtSdate" class="calendar SelectDate" size="10"/> <font color="lightgre en"><strong>* </strong></font>End date of event: <input type="text" name="txtEdate" size="10" class="calendar SelectDate"><br />
      Street Referance: &nbsp;&nbsp;&nb sp;<input type="text" name="txtSref" size="50"><br />

      <br /><hr /><br />

      <center><tabl e name="tblRides" border="0">
      <tr>
      <td>Rides</td>

      <td><font color="lightgre en"><strong>* </strong></font>Required Days</td>

      <td><center>Pri ce</center></td>

      </tr>

      <tr>

      <td>Trampolin e Bungies</td>

      <td><center><in put type="text" name="txtBungie days" size="2" onchange="total _add()"></center></td>

      <td class="price">< center><input type="text" name="txtBungie price" size="7" value="2000.00" disabled></center></td>

      </tr>

      <tr>

      <td>Tarzan Jumping Castel</td>

      <td><center><in put type="text" name="txtBubble days" size="2" onChange="total _add()"></center></td>

      <td class="price">< center><input type="text" name="txtBubble price" size="7" value="1200.00" disabled></center></td>

      </tr>

      <tr>

      <td>Voyager Simulator</td>

      <td><center><in put type="text" name="txtSimday s" size="2" onChange="total _add()"></center></td>

      <td class="price">< center><input type="text" name="txtSimpri ce" size="7" value="1850.00" disabled></center></td>

      </tr>

      <tr>

      <td>Giant Slide</td>

      <td><center><in put type="text" name="txtSlided ays" size="2" onChange="total _add()"></center></td>

      <td class="price">< center><input type="text" name="txtSlidep rice" size="7" value="1850.00" disabled></center></td>

      </tr>

      <tr>

      <td>Food Van</td>

      <td><center><in put type="text" name="txtFvanda ys" size="2" onChange="total _add()"></center></td>

      <td class="price">< center><input type="text" name="txtFvanpr ice" size="7" value="0.00" disabled></center></td>

      </tr>

      <tr>

      <td></td>

      <td>Total Amount Owing: $</td>

      <td class="price">< input type="text" name="txtTotalp rice" size="7" disabled></td>

      </tr>
      </table></center><br />

      <center>Extra Details/Questions: <br /><textarea name="txtCommen ts" rows="8" cols="40">Place any extra details or questions here.</textarea></center><br /><br />

      <center><inpu t type="submit" name="btnSubmit " value="Make Booking"> <input type="reset" name="btnReset" value="Reset the order"></center>
      </form>
      [/html]

      (form 2):
      [html]
      <form name="frmExtras " method="post">
      <li><input type="checkbox" name="chkGen"> Generator (Simulator Only).<input type="hidden" name=txtGenpric e" value="1000" onchange="extra s()"></li>
      <li><input type="checkbox" name="chkLights "> Lights. <br /><input type="text" name="txtLammou nt" value="0" size="2" onchange=""> Ammount needed.<input type="hidden" name=txtLprice" value="1000"></li>
      </form>
      [/html]

      Now what i need is to be able to get the values of 'frmExtras' into the box 'txtTotalprice' if the check box for 'chkGen' is selected or an ammount from 'txtLprice' if 'txtLammount' has a value in it.. ive been trying to nut it out and my own knowledge is just too limited i need help with it... any advice of how to go about it would be great.

      DD

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        threads merged ... DON'T multipost the same questions!

        kind regards
        MOD

        Comment

        • DDragon
          New Member
          • Aug 2007
          • 15

          #5
          appologies, but it would have been better to send me a pm stating you changed the topic rather than do it in the thread as i didnt know what had happend to my thread so i reposted. just a thought

          DD

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by DDragon
            appologies, but it would have been better to send me a pm stating you changed the topic rather than do it in the thread as i didnt know what had happend to my thread so i reposted. just a thought

            DD
            To find your threads, see the subscribed link or the Started link (top of the page).

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by DDragon
              ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other form to it... ill post the code for you to look at and try to explaine in detail what im trying to do. Now what i need is to be able to get the values of 'frmExtras' into the box 'txtTotalprice' if the check box for 'chkGen' is selected or an ammount from 'txtLprice' if 'txtLammount' has a value in it.. ive been trying to nut it out and my own knowledge is just too limited i need help with it... any advice of how to go about it would be great.
              If you want to refer to the form, use document.forms["frmExtras"].elements[elementName]. To check that chkGen is checked:
              [code=javascript]if (document.forms["frmExtras"].elements["chkGen"].checked) {
              ...
              }[/code] To check that txtlAmmount has a value, just check that it isn't equal to empty (!= "").

              Comment

              • DDragon
                New Member
                • Aug 2007
                • 15

                #8
                Thanks for the help acoder, and to respond to your first post i did that but still a pm would be helpful instead of just changing it and making it a post in the thread.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by DDragon
                  Thanks for the help acoder, and to respond to your first post i did that but still a pm would be helpful instead of just changing it and making it a post in the thread.
                  True, a PM would work if everyone knew how to use them. Many simply don't know they exist.

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    Originally posted by DDragon
                    Thanks for the help acoder, and to respond to your first post i did that but still a pm would be helpful instead of just changing it and making it a post in the thread.
                    in case you did you could have seen the change ... and since a thread title 'Help Needed' is not a title where somebody knows what you mean ... remember: nearly all threads in the programming forums are started to solve a problem and thus they are asking for help ... i changed it according to the posting guidelines ... since you only have 2 started threads i cannot imagine that you couldn't have noticed the change without a PM ... but i'll try to remember you and in case the same issue occurs i'll send you a PM regarding the change ...

                    kind regards

                    Comment

                    • DDragon
                      New Member
                      • Aug 2007
                      • 15

                      #11
                      Originally posted by gits
                      in case you did you could have seen the change ... and since a thread title 'Help Needed' is not a title where somebody knows what you mean ... remember: nearly all threads in the programming forums are started to solve a problem and thus they are asking for help ... i changed it according to the posting guidelines ... since you only have 2 started threads i cannot imagine that you couldn't have noticed the change without a PM ... but i'll try to remember you and in case the same issue occurs i'll send you a PM regarding the change ...

                      kind regards
                      Gits, dont take me wrong i ment no offence by my comments it just struck me as odd that i didnt get a pm about it thats all... and i understand the reasons behind changing the topic and i do mean my apology i gave about it. it just confused me where it went thats all as ive only posted here once before (thread wise). I thank you for your understanding with this i will be using the standard for my posts from now on so this situation should not happen again.

                      Thanks again,

                      DD

                      Comment

                      • DDragon
                        New Member
                        • Aug 2007
                        • 15

                        #12
                        Originally posted by acoder
                        If you want to refer to the form, use document.forms["frmExtras"].elements[elementName]. To check that chkGen is checked:
                        [code=javascript]if (document.forms["frmExtras"].elements["chkGen"].checked) {
                        ...
                        }[/code] To check that txtlAmmount has a value, just check that it isn't equal to empty (!= "").
                        so if i replace my 'if' statements in the script regarding the Extras form it should work in Theory?

                        DD

                        (That is true about people not knowing how to use the PM service)

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5390

                          #13
                          no problem ... i just wanted to avoid a discussion between you and acoder concerning that small issue ... usually i don't pm a user unless its an important thing where i want to assure he knows about ...

                          anyway ... just post back to the forum anytime you have more questions :) ... and now i know that you love to have PMs :) ...

                          kind regards

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Originally posted by DDragon
                            so if i replace my 'if' statements in the script regarding the Extras form it should work in Theory?
                            It's the extras() function that needs changing. If you change it to what I've suggested, it should work or at least the first bit. You mentioned about the hidden variable having a value. That should probably go as an else if, e.g.
                            [code=javascript]if (...checked) {
                            // set total
                            } else if (...value != "") {
                            // set total value using hidden variable value
                            }[/code]

                            Comment

                            Working...