473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help needed to get information across forms with javascript

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
13 1814
gits
5,390 Expert Mod 4TB
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
DDragon
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
5,390 Expert Mod 4TB
threads merged ... DON'T multipost the same questions!

kind regards
MOD
Mar 18 '08 #4
DDragon
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
16,027 Expert Mod 8TB
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
16,027 Expert Mod 8TB
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
DDragon
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
16,027 Expert Mod 8TB
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
5,390 Expert Mod 4TB
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
DDragon
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
DDragon
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
5,390 Expert Mod 4TB
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
16,027 Expert Mod 8TB
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

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

Similar topics

4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
8
by: shandain | last post by:
Ok, I have done this a million times, and I can't get this to work... I hope I am just being an idiot and missing something... but I can't see it... so please call me an idiot and tell me what it...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
8
by: Lloyd Sheen | last post by:
I have a problem with persisting the state of a control. It has several properties that can be determined but there is no event to indicate when the property changes. A postback occurs when one...
4
by: Random | last post by:
The way I've built my page is to take the user through a multi-form process, only rendering those controls that are needed for each section. The ViewState is working the way I want it to,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: i | last post by:
what is scripting language?We can create websites by using HTML. But we are using scripting language with HTML to create forms and websites.Advantage of using scripting language instead of HTML?
4
by: dupdupdup | last post by:
Hello there, im needed to develop a gallery for this website. im using hotspots to go to my frames in my flash Each hotspot goes to each frame. The flash is loaded properly. When i right click...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.