|
Prev: Multiple <script type="text/javascript" src="mys.js"></script>OK?
Next: ASP .NET and Javascript
From: Cubicle Intern on 15 Apr 2008 18:28 Hi, I have a form with multiple fields that confirmed before the form is submitted (ex. email field needs to be completed before the form can be submitted). Once the required fields are completed, I want a final warning box to appear asking the user "are you sure you want to make these changes?" I'm having trouble getting the function to work correctly. Here's the problem I've encountered: First Script: this one lets me enter an email into an empty email field and shows the confirmation box but the information in the form is updated regardless of whether I click OK or Cancel. function page_check() { if (check(document.form.txt_EMail.value,true)) { if ((document.form.txt_EMail.value!="") && (check(document.form.txt_EMail.value,false))) document.form.submit(); else { if (document.form.txt_EMail.value=='') alert('Please enter an email.'); return; } if(confirm("Are you sure you want to upload this file?")) { document.form.page_check() return false; } } } Second Script: When I create a separate function with "are you sure you..." warning similar to this: function page_check() { if(confirm("Are you sure you want to upload this file?")) { document.form.page_check() return false; } }else return true; } it does not prompt me to complete the email field. It goes straight to the warning, "are you sure..." However, if I click Cancel, then it does not update, and if I click OK it updates. Any suggestions on how to fix this script so that I can keep the enter email prompt AND the warning prompt? Any help is very much appreciated. Thanks in advance.
From: tomtom.wozniak on 16 Apr 2008 00:19 On Apr 15, 5:28 pm, Cubicle Intern <vyts...(a)gmail.com> wrote: > Hi, > > I have a form with multiple fields that confirmed before the form is > submitted (ex. email field needs to be completed before the form can > be submitted). Once the required fields are completed, I want a final > warning box to appear asking the user "are you sure you want to make > these changes?" I'm having trouble getting the function to work > correctly. Here's the problem I've encountered: > > First Script: this one lets me enter an email into an empty email > field and shows the confirmation box but the information in the form > is updated regardless of whether I click OK or Cancel. > > function page_check() > { > if (check(document.form.txt_EMail.value,true)) > { > if ((document.form.txt_EMail.value!="") && > (check(document.form.txt_EMail.value,false))) > document.form.submit(); > else > { > if (document.form.txt_EMail.value=='') > alert('Please enter an email.'); > return; > } > > if(confirm("Are you sure you want to upload this file?")) > { > document.form.page_check() > return false; > } > } > > } > > Second Script: When I create a separate function with "are you sure > you..." warning similar to this: > > function page_check() > { if(confirm("Are you sure you want to upload this file?")) > { > document.form.page_check() > return false; > } > }else > return true; > > } > > it does not prompt me to complete the email field. It goes straight > to the warning, "are you sure..." However, if I click Cancel, then it > does not update, and if I click OK it updates. > > Any suggestions on how to fix this script so that I can keep the enter > email prompt AND the warning prompt? > > Any help is very much appreciated. Thanks in advance. Let me know if this is of any use. Specifically, I would access the form field via "document.forms[0]" instead of "document.form". Note that onSubmit wants a true or false value from the returning function. If onSubmit receives false, form.submit never fires (you don't have to explicitly submit within your function call. When onSubmit receives true, the current values entered in the form will be sent to the server. <html> <head> <script> function errorfree (initialValue,errorValue,msg) { var err = (initialValue == errorValue); if (err) if( msg || '' != '' ) alert (msg); return (! err); } </script> </head> <body> <form method="GET" action="" onSubmit="return errorfree (document.forms[0].txt_EMail.value || '','','Please enter an email.')"> <input name="txt_EMail" id="txt_EMail" /> <input type="submit" /> </form> </body> </html> -Tom Woz
From: Cubicle Intern on 16 Apr 2008 13:45 On Apr 15, 9:19 pm, tomtom.wozn...(a)gmail.com wrote: > On Apr 15, 5:28 pm, Cubicle Intern <vyts...(a)gmail.com> wrote: > > > > > > > Hi, > > > I have a form with multiple fields that confirmed before the form is > > submitted (ex. email field needs to be completed before the form can > > be submitted). Once the required fields are completed, I want a final > > warning box to appear asking the user "are you sure you want to make > > these changes?" I'm having trouble getting the function to work > > correctly. Here's the problem I've encountered: > > > First Script: this one lets me enter an email into an empty email > > field and shows the confirmation box but the information in the form > > is updated regardless of whether I click OK or Cancel. > > > function page_check() > > { > > if (check(document.form.txt_EMail.value,true)) > > { > > if ((document.form.txt_EMail.value!="") && > > (check(document.form.txt_EMail.value,false))) > > document.form.submit(); > > else > > { > > if (document.form.txt_EMail.value=='') > > alert('Please enter an email.'); > > return; > > } > > > if(confirm("Are you sure you want to upload this file?")) > > { > > document.form.page_check() > > return false; > > } > > } > > > } > > > Second Script: When I create a separate function with "are you sure > > you..." warning similar to this: > > > function page_check() > > { if(confirm("Are you sure you want to upload this file?")) > > { > > document.form.page_check() > > return false; > > } > > }else > > return true; > > > } > > > it does not prompt me to complete the email field. It goes straight > > to the warning, "are you sure..." However, if I click Cancel, then it > > does not update, and if I click OK it updates. > > > Any suggestions on how to fix this script so that I can keep the enter > > email prompt AND the warning prompt? > > > Any help is very much appreciated. Thanks in advance. > > Let me know if this is of any use. Specifically, I would access the > form field via "document.forms[0]" instead of "document.form". > > Note that onSubmit wants a true or false value from the returning > function. If onSubmit receives false, form.submit never fires (you > don't have to explicitly submit within your function call. When > onSubmit receives true, the current values entered in the form will be > sent to the server. > > <html> > <head> > <script> > function errorfree (initialValue,errorValue,msg) { > var err = (initialValue == errorValue); > if (err) if( msg || '' != '' ) alert (msg); > return (! err); > } > </script> > </head> > <body> > <form method="GET" action="" onSubmit="return errorfree > (document.forms[0].txt_EMail.value || '','','Please enter an > email.')"> > <input name="txt_EMail" id="txt_EMail" /> > <input type="submit" /> > </form> > </body> > </html> > > -Tom Woz- Hide quoted text - > > - Show quoted text - Hi, Thanks for the help but unfortunately it didn't work as well as I hoped it would. Would you be able to suggest how to apply multiple if/ else statements to the function above? tyv
From: Cubicle Intern on 16 Apr 2008 16:44 On Apr 15, 9:19 pm, tomtom.wozn...(a)gmail.com wrote: > On Apr 15, 5:28 pm, Cubicle Intern <vyts...(a)gmail.com> wrote: > > > > > > > Hi, > > > I have a form with multiple fields that confirmed before the form is > > submitted (ex. email field needs to be completed before the form can > > be submitted). Once the required fields are completed, I want a final > > warning box to appear asking the user "are you sure you want to make > > these changes?" I'm having trouble getting the function to work > > correctly. Here's the problem I've encountered: > > > First Script: this one lets me enter an email into an empty email > > field and shows the confirmation box but the information in the form > > is updated regardless of whether I click OK or Cancel. > > > function page_check() > > { > > if (check(document.form.txt_EMail.value,true)) > > { > > if ((document.form.txt_EMail.value!="") && > > (check(document.form.txt_EMail.value,false))) > > document.form.submit(); > > else > > { > > if (document.form.txt_EMail.value=='') > > alert('Please enter an email.'); > > return; > > } > > > if(confirm("Are you sure you want to upload this file?")) > > { > > document.form.page_check() > > return false; > > } > > } > > > } > > > Second Script: When I create a separate function with "are you sure > > you..." warning similar to this: > > > function page_check() > > { if(confirm("Are you sure you want to upload this file?")) > > { > > document.form.page_check() > > return false; > > } > > }else > > return true; > > > } > > > it does not prompt me to complete the email field. It goes straight > > to the warning, "are you sure..." However, if I click Cancel, then it > > does not update, and if I click OK it updates. > > > Any suggestions on how to fix this script so that I can keep the enter > > email prompt AND the warning prompt? > > > Any help is very much appreciated. Thanks in advance. > > Let me know if this is of any use. Specifically, I would access the > form field via "document.forms[0]" instead of "document.form". > > Note that onSubmit wants a true or false value from the returning > function. If onSubmit receives false, form.submit never fires (you > don't have to explicitly submit within your function call. When > onSubmit receives true, the current values entered in the form will be > sent to the server. > > <html> > <head> > <script> > function errorfree (initialValue,errorValue,msg) { > var err = (initialValue == errorValue); > if (err) if( msg || '' != '' ) alert (msg); > return (! err); > } > </script> > </head> > <body> > <form method="GET" action="" onSubmit="return errorfree > (document.forms[0].txt_EMail.value || '','','Please enter an > email.')"> > <input name="txt_EMail" id="txt_EMail" /> > <input type="submit" /> > </form> > </body> > </html> > > -Tom Woz- Hide quoted text - > > - Show quoted text - So I modified my script but whenever I click Cancel or OK it still updates everything in the form. Any suggestions are very much appreciated. This is what it looks like now: function page_check_pwd() { if (check_pwd(document.frm.txt_EMail.value,true)) { if ((document.frm.txt_EMail.value!="") && (check_pwd(document.form.txt_EMail.value,false))) document.form.submit(); else { if (document.frm.txt_EMail.value=="") alert('Please enter an email.'); return false; } if(confirm("Are you sure you want to make these changes?")) { document.form.submit() return true; } else return false; } }
From: tomtom.wozniak on 17 Apr 2008 14:36 On Apr 16, 3:44 pm, Cubicle Intern <vyts...(a)gmail.com> wrote: > On Apr 15, 9:19 pm, tomtom.wozn...(a)gmail.com wrote: > > > > > On Apr 15, 5:28 pm, Cubicle Intern <vyts...(a)gmail.com> wrote: > > > > Hi, > > > > I have a form with multiple fields that confirmed before the form is > > > submitted (ex. email field needs to be completed before the form can > > > be submitted). Once the required fields are completed, I want a final > > > warning box to appear asking the user "are you sure you want to make > > > these changes?" I'm having trouble getting the function to work > > > correctly. Here's the problem I've encountered: > > > > First Script: this one lets me enter an email into an empty email > > > field and shows the confirmation box but the information in the form > > > is updated regardless of whether I click OK or Cancel. > > > > function page_check() > > > { > > > if (check(document.form.txt_EMail.value,true)) > > > { > > > if ((document.form.txt_EMail.value!="") && > > > (check(document.form.txt_EMail.value,false))) > > > document.form.submit(); > > > else > > > { > > > if (document.form.txt_EMail.value=='') > > > alert('Please enter an email.'); > > > return; > > > } > > > > if(confirm("Are you sure you want to upload this file?")) > > > { > > > document.form.page_check() > > > return false; > > > } > > > } > > > > } > > > > Second Script: When I create a separate function with "are you sure > > > you..." warning similar to this: > > > > function page_check() > > > { if(confirm("Are you sure you want to upload this file?")) > > > { > > > document.form.page_check() > > > return false; > > > } > > > }else > > > return true; > > > > } > > > > it does not prompt me to complete the email field. It goes straight > > > to the warning, "are you sure..." However, if I click Cancel, then it > > > does not update, and if I click OK it updates. > > > > Any suggestions on how to fix this script so that I can keep the enter > > > email prompt AND the warning prompt? > > > > Any help is very much appreciated. Thanks in advance. > > > Let me know if this is of any use. Specifically, I would access the > > form field via "document.forms[0]" instead of "document.form". > > > Note that onSubmit wants a true or false value from the returning > > function. If onSubmit receives false, form.submit never fires (you > > don't have to explicitly submit within your function call. When > > onSubmit receives true, the current values entered in the form will be > > sent to the server. > > > <html> > > <head> > > <script> > > function errorfree (initialValue,errorValue,msg) { > > var err = (initialValue == errorValue); > > if (err) if( msg || '' != '' ) alert (msg); > > return (! err); > > } > > </script> > > </head> > > <body> > > <form method="GET" action="" onSubmit="return errorfree > > (document.forms[0].txt_EMail.value || '','','Please enter an > > email.')"> > > <input name="txt_EMail" id="txt_EMail" /> > > <input type="submit" /> > > </form> > > </body> > > </html> > > > -Tom Woz- Hide quoted text - > > > - Show quoted text - > > So I modified my script but whenever I click Cancel or OK it still > updates everything in the form. Any suggestions are very much > appreciated. This is what it looks like now: > > function page_check_pwd() > { > if (check_pwd(document.frm.txt_EMail.value,true)) > { > if ((document.frm.txt_EMail.value!="") && > (check_pwd(document.form.txt_EMail.value,false))) > document.form.submit(); > else > { > if (document.frm.txt_EMail.value=="") > alert('Please enter an email.'); > return false; > } > > if(confirm("Are you sure you want to make these changes?")) > { > document.form.submit() > return true; > } else > return false; > > } > } I cleaned up your latest code. Let me know if this is what you're looking for. function page_check_pwd() { var result = false; // only set to true when validated. if (check_pwd(document.frm.txt_EMail.value,true)) { if ((document.frm.txt_EMail.value!="") && (check_pwd(document.form.txt_EMail.value,false))) { if (confirm("Are you sure you want to make these changes?")) { result = true; } } else { if (document.frm.txt_EMail.value=="") { alert('Please enter an email.'); } } } return result; } -Tom Woz
|
Next
|
Last
Pages: 1 2 Prev: Multiple <script type="text/javascript" src="mys.js"></script>OK? Next: ASP .NET and Javascript |