Solved

Add reset button without resetting certain fields.

Posted on 1998-07-25
25
473 Views
Last Modified: 2012-06-27
I have a web page at www.modernmenus.com/sample (its frames and target page is under main.htm) How do I add a reset button without resetting following fields subtotal, taxes, total and order? Its for customers who would like to order multiple orders like one order of wings(10) hot and another one of wings(10) regular.(target browsers ie3 and netscape3 and above)
Thanks Hank hoster19@idt.net
0
Comment
Question by:hoster19
  • 15
  • 10
25 Comments
 
LVL 8

Expert Comment

by:jbirk
ID: 1267189
OK, if there are a lot of fields, the easiest way is to save the few which you don't want modified and just reset the others, if there are only a few fields which are getting cleared, then it's easier to explicitly clear those fields.

Either way, using:
<INPUT type=button onClick="clearForm();" value="reset">
will replace your reset button.
Then depending on which method applies, the function would vary.
Tell me which one applies, and I can write a quick function for you.

-Josh
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267190
Since I had a little extra time, below is an example of what would work in the case that you have a lot of fields which get cleared and only a few which get saved.  This example assumes a form which is named 'form_name'.

<script language="Javascript">
<!--
// store user fields in variables
var subtotal, taxes, total, order;

function clearFrom()
{ // store user fields in variables
subtotal = document.form_name.subtotal.value;
taxes = document.form_name.taxes.value;
total = document.form_name.total.value;
order = document.form_name.order.value;
// reset entire form
form.reset();
setTimeout("clearForm2();",500);
} //wait .5 seconds to clear them out so that
// reset will occur first

function clearForm2()
{ // alert(form.User_Name.value);
// restore saved variables
var subtotal, taxes, total, order;
document.form_name.subtotal.value = subtotal;
document.form_name.taxes.value = taxes;
document.form_name.total.value = total;
document.form_name.order.value = order;
}
// -->
</script>
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267191
oh woops... forgot to change a line (this copy/pasted).
the line:
form.reset();
should be changed to:
document.form_name.reset();
0
 

Author Comment

by:hoster19
ID: 1267192
I think I have some minor problems....It tells me clearForm is not defined.....I fixed some minor problems(I think) like "" around button....and then I had to change all those form names....I don't think I have a form name under main.htm(Do I need to add one?) I'm using fp98 so take a look www.modernmenus.com/sample (I added reset button next to "wings" so what I want is keep the numbers same in lower left corner and at the bottom of the main form.
Hank  
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267193
OK, I found a couple of problems...
1. I accidentally mistyped clearForm as clearFrom in the definition of the function.  So make sure to fix that typo.
2. You didn't name your form.  Just insert name="theForm" in the form tag.  It should work now, but there were a couple other things that might cause problems:
3. the reset tag doesn't have the closing '>'  The browser seems to operate without this but I'm not sure if all browsers will be capable of recovering from that.
4. The <HEAD> tag should be before any of the javascript and you put it between the two javascript sections.

Hope this fixes it for you!
-Josh
0
 

Author Comment

by:hoster19
ID: 1267194
I did above changes and it does fine by not changing values on left lower frame, but it does not keep fields on bottom of main form...tells me not defined????
we are getting there....
Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267195
OK, first of all, when you do form.reset(), it only resets that form, so the form on the left frame isn't touched because it's a seperate form.  Then, the stuff on the main page isn't working because a line crept into the following function:

function clearForm2()
{ // alert(form.User_Name.value);
// restore saved variables
var SubTotal, Taxes, Total, Order;  //this line shouldn't be here
document.theForm.SubTotal.value = SubTotal;
document.theForm.Taxes.value = Taxes;
document.theForm.Total.value = Total;
document.theForm.Order.value = Order;
}

What's happening is that the new local variable defined by that line are overiding the global variables which were used to save the values, so since the haven't been assigned a value yet (the local ones), they're undefined.

-Josh
0
 

Author Comment

by:hoster19
ID: 1267196
I increased point for you because You have been working very closely with this so I'll try to reward you all the points I got so far...
It works fine now, except when I click another order it will clear everything from fields so Actually ends up like resetting everything....I would like to keep info and resetting with the button I created would act like add to shopping cart button, then user would be able to continue ordering with hes previous order in "memory"="order field" (plus I would like to keep all the prices in memory too) (How about when I reset all how would I be able to reset amounts in left lower frame?) Hopefully You understand what I mean, if not let me know....
Ps I'm trying to use javascript cause I thing its more friendlier than CGI and all this code what I have is from here by asking tons of questions and burning all my points....so This is all I got If You dont want to continueany more please let me know and I'll give you the points, because you helped me more than enough allready.
Thanks Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267197
K, I will look into this later.  (I'm working tonight)
-Josh
0
 

Author Comment

by:hoster19
ID: 1267198
Ok
Here it goes. I just added the stuff on a page www.modernmenus.com/sample (Pizza....) Again page is under (main.htm)to build a code.
What I want is customer to be able to build his own pizza and It would calculate and add his/her order to "Order box" plus for their convinience I need to show total amounts in bottom of the order and on left lower frame. All this is important because I will use that info to send an order to restaurant. I need to have this working atleast NN3 and IE3 and Above, I will let you have this first if you want to keep working because I think all this relates together. (So understand When customer order something from menu and then wants to add pizza (Build one) it would still add and show every order on "order" box"
I Wish I new Javascript like You guys do.........
Hank hoster19@idt.net
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267199
OK, I don't have time to work this all out now (this is getting quite complex isn't it)?

Anyway, I see the problem causing your first question above about selecting more items.  It's because it changes that textarea at the bottom of the form to hold the values of all the select fields which are changed each time you change one.  So when you reset those selects using the reset button I set up for you, it removes those from being checked, and then if you select another item, that's the only one that's selected so it overwrites what was in the textarea before.

So what will have to be done is some way to save the value of the textarea when the form is reset via the button that I helped you with.  Then a couple modifications to the ossi() function will be necesary as well.

Anyway on to the pizza question...  This will involve setting up another whole javascript program.  Is this pizza thing going to be on the same page or on a different page?  If it's going to be on a different page it will be easier so we don't have to deal with all the other stuff that's on that page.

You know, I was thinking that perhaps using cookies for this page might not be a bad idea...  but that would take quite a bit more work.  I'll work on the two above questions later today (I have a meeting today at 10:00)

-Josh
0
 

Author Comment

by:hoster19
ID: 1267200
I would like to keep everything in one page and I would like to have it working atleast with nn3 and ie 3 and above. I will open this to others as well, so we might get some other suggestions.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 8

Accepted Solution

by:
jbirk earned 250 total points
ID: 1267201
If you wanted to get others helping as well, you should make seperate questions for each part, each worth a smaller amount of points.  I've worked a lot on this already, if some else came in and answered the question with the mods needed for the last two steps, all my work would be worth no points.  I am doing this to be helpfull, but I also like to get the points.  So please don't reject a good accepted answer because you've added on new things to do.

I will work on these things later today.  I already know how to do it, it just takes a little while to code it.
-Josh
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267202
Oh, and others can interject there suggestions at any time even if it's locked.  I think they are avoiding it because:
1. It's so long now it would take forever to read it all
2. I've done a lot of work on it already and they don't want to bother because they figure I'll be able to handle it (and I can)

-Josh
0
 

Author Comment

by:hoster19
ID: 1267203
Hey I did not mean to reject your answer ,but thought maybe you could get some advice (I did not know people would be able to proposed comments when question is allready answered) And like doing in it past I split 500 points for code which was allready in a page (I thought I would do same except give you allready for those 250 points, and I will give you more when ever I can get some....I know you worked very hard and its allright if we (You) do it simpler way (just tell me if that is too complex to do then we do something little bit simpler (You still get points) Talking about cookies I dont think thats a good idea (Dont most people turn cookies off....which would mean they are unable to use menu...) So if you can think of simpler way to do that let me know.
Like I said you are one of the best out there....
I might even consider hiring your services....But for now points only...
Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267204
Thanks for the compliment!
There's no need to do it a simpler way, I just thought that the page was getting rather large.  It's fine as it is, and the links on the side help to navigate the large page (you need to add one for pizza though now).  Also, for me the price fields on the bottom left are slightly cut off.  I have a 600 X 800 screen.  You must have a larger screen, but there's still a  large number of people with 800 X 600 and 640 X 480, so if you could maybe have those a little higher it would work better for all the screen sizes.

So, anyway on to the next two tasks. I think to fix that error where the order description was dissapearing, only small modifications are necesary.  It's hard to know for sure without testing it, but try this:
change this line:
var SubTotal, Taxes, Total, Order;
to this:
var SubTotal, Taxes, Total, Order="";

and then in the function Ossi(), change this line (near the bottom of the function):
theForm.Order.value = display;
to this:
theForm.Order.value = Order + display;

Beleive it or not, that may be all that's necesary.  Try it out.  If not, I'll look into it at work tomorrow.

And then for the pizza order thing, I'm still thinking about the best way to do that without using tons of code (although easy to write code it could get long like the ossi() function did, and this page is getting to be rather large for a text document!)

I'll get back to you on it tomorrow.

-Josh
P.S. Are you doing this whole site on your own?  It looks pretty good so far, I'd like to know how the idea works out.
0
 

Author Comment

by:hoster19
ID: 1267205
You are the MAN !!!!
Its working YES!

But quess what when I reset the whole form it still keeps values on lower left corner???

BTW I know it looks different on Netscape than IE so I will change that later to look good.
Question how will I set up IE3 and Netscape 3 on my machine it wont allow to overwrite my w98 IE4 (Don't spend too much on this if you know what I mean I dont have points for that question....heheh)
Hank
0
 

Author Comment

by:hoster19
ID: 1267206
Would you like to get all files within frames?
I can E-mail them to you...
Would you be interested to have your own CD of MS Visual Studio98?
Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267207
You can't install IE4 AND IE3 on the same machine (d**n Microsoft).  I wish you could though, cause I'd also like to be able to test IE 3, but can't.  So you'd have to find another machine which you don't need IE 4 on to install and test with IE 3.  As far as Netscape goes, you can install all netscapes on the same machine (and it even runs right off of a disk because it requires no mods to OS or the registry).

The values in the lower left frame are another thing alltogether.  There's just a few functionalities we'll have to add to the reset button, but that's easy stuff.

As far as the files in the frames...  I don't really need them.  I just make copies of the files I need to run on my hard drive by saving the source (of course some JavaScript sections which include document.write's don't get saved, but it's not that important in this case).

What's in MS Visual Studio98?  I might be interested, but I don't know what's in it.

-Josh
0
 

Author Comment

by:hoster19
ID: 1267208
Visual Basic 6, Visual C++ 6 Visual FoxPro, Visual Interdev....
The whole enchilada.....Latest too
Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267209
Wohoo!  I'd love to have that.  It's a legal copy right?  I've been wanting to get a hold of VB 6 so I can learn VB.

-Josh
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267210
OK, here is what to do to get the reset button to properly clear all the fields:
insetad of the line:
<input TYPE="RESET" VALUE="Reset Form">
use a user defined button again:
<input type="button" value="Reset Form" onClick="clearAll()">
Then in the header javascript area, insert this function:
function clearAll()
{SubTotal=0;
 Taxes=0;
 Total=0;
 Order="";
 parent.Totals.document.TotalsForm.SubTotal.value=0;
 parent.Totals.document.TotalsForm.Taxes.value=0;
 parent.Totals.document.TotalsForm.Total.value=0;
}

That was an easy one.
The pizza one is not, because there will need to be error checking like if the user picks a medium Sicilian, or a White Pizza with topings selected.  (of course this is also basic javascript stuff, but requires more code than some really complicated stuff)
Also, I see extra cheese as an option but no way to order that.
I'll post the necesary code later tonight probably.
-Josh
0
 

Author Comment

by:hoster19
ID: 1267211
Did not work, but I think I fixed it I changed your code to following:
function clearAll()
{
theForm.SubTotal.value=0;
theForm.Taxes.value=0;
theForm.Total.value=0;
theForm.Order.value="";
parent.Totals.document.TotalsForm.SubTotal.value=0;
parent.Totals.document.TotalsForm.Taxes.value=0;
parent.Totals.document.TotalsForm.Total.value=0;
document.theForm.reset();
}
function getRadiovalue(r) {
for (var i=0;i<r.length;i++) if (r[i].checked) return r[i].value;
return '';
}

Why dont you send me your E-mail and we can finish this there,
I will give your points right away then....
NP if not
Hank
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267212
That's easy enough.  It's easier to send files as well.
jbirk@kent.edu

My code will work fine, except I forgot one silly line.  Put
document.theForm.reset();
at the end of my function.
The lines:
SubTotal=0;
Taxes=0;
Total=0;
Order="";
are necesary to properly clear the internal values saved when you click the partial reset, and the lines you had:
theForm.SubTotal.value=0;
      theForm.Taxes.value=0;
      theForm.Total.value=0;
      theForm.Order.value="";
are not necesary because the reset() will clear those fields.
Sorry about the confusion.
When you send me your e-mail address and the entire page (with the frames as well) to the address I listed above I will send you the entire pages back with the working code (I will be able to test it better this way as well). I will work on the function in the meantime until I receive that e-mail.
-Josh
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1267213
Did the last version I sent you work for you?
If so, can you grade my answer?
-Josh
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now