By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,838 Members | 2,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,838 IT Pros & Developers. It's quick & easy.

Help needed to get information across forms with javascript

P: 15
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:
Expand|Select|Wrap|Line Numbers
  1. var gen, lights;
  2.  
  3. var lammount;
  4.  
  5.  
  6.  
  7. function validatetheform()
  8.     {
  9.         if (!document.frmTorder.txtBname.value)
  10.             {
  11.                 alert("Please enter your buisness name.");
  12.                 document.frmTorder.txtBname.focus();
  13.             }
  14.  
  15.         else if(!document.frmTorder.txtBaddy.value)
  16.             {
  17.                 alert("Please enter you Buisness address.");
  18.                 document.frmTorder.txtBaddy.focus();
  19.             }
  20.  
  21.         else if(!document.frmTorder.txtPcode.value)
  22.             {
  23.                 alert("Plese enter your postcode");
  24.                 document.frmTorder.txtPcode.focus();
  25.             }
  26.  
  27.         else if(!document.frmTorder.txtState.value)
  28.             {
  29.                 alert("Please enter you state.");
  30.                 document.frmTorder.txtState.focus();
  31.             }
  32.  
  33.         else if(!document.frmTorder.txtSite.value)
  34.             {
  35.                 alert("Please enter the event address.");
  36.                 document.frmTorder.txtSite.focus();
  37.             }
  38.  
  39.         return true;
  40.     }
  41.  
  42.  
  43. function total_add()
  44.     {
  45.  
  46.         var bubbleday, simday, slideday, bungiesday;
  47.         var bubble, sim, slide, bungies;
  48.         var bubblet, simt, slidet, bungiest;
  49.  
  50.         var total;
  51.  
  52.         // Setting the value for the days
  53.         bubbleday = document.frmTorder.txtBubbledays.value;
  54.         simday = document.frmTorder.txtSimdays.value;
  55.         slideday = document.frmTorder.txtSlidedays.value;
  56.         bungiesday = document.frmTorder.txtBungiedays.value;
  57.  
  58.         // setting the value for the set price
  59.         bubble = document.frmTorder.txtBubbleprice.value;
  60.         sim = document.frmTorder.txtSimprice.value;
  61.         slide = document.frmTorder.txtSlideprice.value;
  62.         bungies = document.frmTorder.txtBungieprice.value;
  63.  
  64.         // calculating the total of the individual rides
  65.         bungiest = bungies * bungiesday;
  66.         simt = sim * simday;
  67.         slidet = slide * slideday;
  68.         bubblet = bubble * bubbleday;
  69.  
  70.         // setting the value total with the ammounts from the rides
  71.         total = bubblet + slidet + simt + bungiest;
  72.  
  73.         document.frmTorder.txtTotalprice.value = total;
  74.  
  75.     }
  76.  
  77.  
  78.  
  79. function extras()
  80.  
  81.     {
  82.         if (document.frmExtras.chkGen = selected)
  83.  
  84.             {
  85.  
  86.                 gen = document.frmExtras.txtGenprice.value;
  87.  
  88.             }
  89.  
  90.  
  91.  
  92.         alert("Gen amount is: " + gen);
  93.  
  94.     }
  95.  
and the html (form 1):

Expand|Select|Wrap|Line Numbers
  1. <form name="frmTorder" method="post" onSubmit="validatetheform()" onReset="document.frmTorder.txtBname.focus()">
  2.                 <font color="lightgreen"><strong>*</strong></font>Buisness Name: &nbsp;<input type="text" name="txtBname" size="20"><br />
  3.                 <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 />
  4.                 <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 />
  5.  
  6.                 <br /><hr /><br />
  7.  
  8.                 <font color="lightgreen"><strong>*</strong></font>Address of event: &nbsp;&nbsp;<input type="text" name="txtSite" size="50"><br />
  9.  
  10.                 <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 />
  11.                 Street Referance: &nbsp;&nbsp;&nbsp;<input type="text" name="txtSref" size="50"><br />
  12.  
  13.                 <br /><hr /><br />
  14.  
  15.                 <center><table name="tblRides" border="0">
  16.                     <tr>
  17.                         <td>Rides</td>
  18.  
  19.                         <td><font color="lightgreen"><strong>*</strong></font>Required Days</td>
  20.  
  21.                         <td><center>Price</center></td>
  22.  
  23.                     </tr>
  24.  
  25.                     <tr>
  26.  
  27.                         <td>Trampoline Bungies</td>
  28.  
  29.                         <td><center><input type="text" name="txtBungiedays" size="2" onchange="total_add()"></center></td>
  30.  
  31.                         <td class="price"><center><input type="text" name="txtBungieprice" size="7" value="2000.00" disabled></center></td>
  32.  
  33.                     </tr>
  34.  
  35.                     <tr>
  36.  
  37.                         <td>Tarzan Jumping Castel</td>
  38.  
  39.                         <td><center><input type="text" name="txtBubbledays" size="2" onChange="total_add()"></center></td>
  40.  
  41.                         <td class="price"><center><input type="text" name="txtBubbleprice" size="7" value="1200.00" disabled></center></td>
  42.  
  43.                     </tr>
  44.  
  45.                     <tr>
  46.  
  47.                         <td>Voyager Simulator</td>
  48.  
  49.                         <td><center><input type="text" name="txtSimdays" size="2" onChange="total_add()"></center></td>
  50.  
  51.                         <td class="price"><center><input type="text" name="txtSimprice" size="7" value="1850.00" disabled></center></td>
  52.  
  53.                     </tr>
  54.  
  55.                     <tr>
  56.  
  57.                         <td>Giant Slide</td>
  58.  
  59.                         <td><center><input type="text" name="txtSlidedays" size="2" onChange="total_add()"></center></td>
  60.  
  61.                         <td class="price"><center><input type="text" name="txtSlideprice" size="7" value="1850.00" disabled></center></td>
  62.  
  63.                     </tr>
  64.  
  65.                     <tr>
  66.  
  67.                         <td>Food Van</td>
  68.  
  69.                         <td><center><input type="text" name="txtFvandays" size="2" onChange="total_add()"></center></td>
  70.  
  71.                         <td class="price"><center><input type="text" name="txtFvanprice" size="7" value="0.00" disabled></center></td>
  72.  
  73.                     </tr>
  74.  
  75.                     <tr>
  76.  
  77.                         <td></td>
  78.  
  79.                         <td>Total Amount Owing: $</td>
  80.  
  81.                         <td class="price"><input type="text" name="txtTotalprice" size="7" disabled></td>
  82.  
  83.                     </tr>
  84.                 </table></center><br />
  85.  
  86.                 <center>Extra Details/Questions: <br /><textarea name="txtComments" rows="8" cols="40">Place any extra details or questions here.</textarea></center><br /><br />
  87.  
  88.                 <center><input type="submit" name="btnSubmit" value="Make Booking"> <input type="reset" name="btnReset" value="Reset the order"></center>
  89.             </form>
  90.  
(form 2):
Expand|Select|Wrap|Line Numbers
  1. <form name="frmExtras" method="post">
  2.                     <li><input type="checkbox" name="chkGen"> Generator (Simulator Only).<input type="hidden" name=txtGenprice" value="1000" onchange="extras()"></li>
  3.                     <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>
  4.                 </form>
  5.  
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
Mar 18 '08 #1
Share this Question
Share on Google+
13 Replies


gits
Expert Mod 5K+
P: 5,295
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
Mar 18 '08 #2

P: 15
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:
Expand|Select|Wrap|Line Numbers
  1. var gen, lights;
  2.  
  3. var lammount;
  4.  
  5.  
  6.  
  7. function validatetheform()
  8.     {
  9.         if (!document.frmTorder.txtBname.value)
  10.             {
  11.                 alert("Please enter your buisness name.");
  12.                 document.frmTorder.txtBname.focus();
  13.             }
  14.  
  15.         else if(!document.frmTorder.txtBaddy.value)
  16.             {
  17.                 alert("Please enter you Buisness address.");
  18.                 document.frmTorder.txtBaddy.focus();
  19.             }
  20.  
  21.         else if(!document.frmTorder.txtPcode.value)
  22.             {
  23.                 alert("Plese enter your postcode");
  24.                 document.frmTorder.txtPcode.focus();
  25.             }
  26.  
  27.         else if(!document.frmTorder.txtState.value)
  28.             {
  29.                 alert("Please enter you state.");
  30.                 document.frmTorder.txtState.focus();
  31.             }
  32.  
  33.         else if(!document.frmTorder.txtSite.value)
  34.             {
  35.                 alert("Please enter the event address.");
  36.                 document.frmTorder.txtSite.focus();
  37.             }
  38.  
  39.         return true;
  40.     }
  41.  
  42.  
  43. function total_add()
  44.     {
  45.  
  46.         var bubbleday, simday, slideday, bungiesday;
  47.         var bubble, sim, slide, bungies;
  48.         var bubblet, simt, slidet, bungiest;
  49.  
  50.         var total;
  51.  
  52.         // Setting the value for the days
  53.         bubbleday = document.frmTorder.txtBubbledays.value;
  54.         simday = document.frmTorder.txtSimdays.value;
  55.         slideday = document.frmTorder.txtSlidedays.value;
  56.         bungiesday = document.frmTorder.txtBungiedays.value;
  57.  
  58.         // setting the value for the set price
  59.         bubble = document.frmTorder.txtBubbleprice.value;
  60.         sim = document.frmTorder.txtSimprice.value;
  61.         slide = document.frmTorder.txtSlideprice.value;
  62.         bungies = document.frmTorder.txtBungieprice.value;
  63.  
  64.         // calculating the total of the individual rides
  65.         bungiest = bungies * bungiesday;
  66.         simt = sim * simday;
  67.         slidet = slide * slideday;
  68.         bubblet = bubble * bubbleday;
  69.  
  70.         // setting the value total with the ammounts from the rides
  71.         total = bubblet + slidet + simt + bungiest;
  72.  
  73.         document.frmTorder.txtTotalprice.value = total;
  74.  
  75.     }
  76.  
  77.  
  78.  
  79. function extras()
  80.  
  81.     {
  82.         if (document.frmExtras.chkGen = selected)
  83.  
  84.             {
  85.  
  86.                 gen = document.frmExtras.txtGenprice.value;
  87.  
  88.             }
  89.  
  90.  
  91.  
  92.         alert("Gen amount is: " + gen);
  93.  
  94.     }
  95.  
and the html (form 1):

[html]
<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;&n bsp;&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;&n bsp;<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;<inpu t 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>
[/html]

(form 2):
[html]
<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>
[/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
Mar 18 '08 #3

gits
Expert Mod 5K+
P: 5,295
threads merged ... DON'T multipost the same questions!

kind regards
MOD
Mar 18 '08 #4

P: 15
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
Mar 18 '08 #5

acoder
Expert Mod 15k+
P: 16,027
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).
Mar 18 '08 #6

acoder
Expert Mod 15k+
P: 16,027
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:
Expand|Select|Wrap|Line Numbers
  1. if (document.forms["frmExtras"].elements["chkGen"].checked) {
  2. ...
  3. }
To check that txtlAmmount has a value, just check that it isn't equal to empty (!= "").
Mar 18 '08 #7

P: 15
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.
Mar 19 '08 #8

acoder
Expert Mod 15k+
P: 16,027
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.
Mar 19 '08 #9

gits
Expert Mod 5K+
P: 5,295
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
Mar 19 '08 #10

P: 15
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
Mar 19 '08 #11

P: 15
If you want to refer to the form, use document.forms["frmExtras"].elements[elementName]. To check that chkGen is checked:
Expand|Select|Wrap|Line Numbers
  1. if (document.forms["frmExtras"].elements["chkGen"].checked) {
  2. ...
  3. }
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)
Mar 19 '08 #12

gits
Expert Mod 5K+
P: 5,295
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
Mar 19 '08 #13

acoder
Expert Mod 15k+
P: 16,027
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.
Expand|Select|Wrap|Line Numbers
  1. if (...checked) {
  2. // set total
  3. } else if (...value != "") {
  4.   // set total value using hidden variable value
  5. }
Mar 19 '08 #14

Post your reply

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