House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  Javascript

ColdFusion losing Variable value after calling JavaScript

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
jennifer fiers
11/19/2007 08:46 AM

I am a newbie to ColdFusion and Javascript. I am trying to perform validation on a coldfusion webpage before letting the user leave the page. The javascript is working however, after the alert is shown to the user the CF page errors because a url variable I passed loses its value. I use this command when I first enter the page <cfset variables.docnum= #url.docnum#>. How can I keep this value when the javascript returns? Any help would be appreciated.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/19/2007 10:19 AM

>>How can I keep this value when the javascript returns? Any help would be appreciated. The value is not supposed to be lost. So there must be something wrong your Javascript is doing. Hard to say if you don't show your script. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
jennifer fiers
11/19/2007 11:04 AM

----- Excess quoted text cut - see Original Post for more ----- Here is the validation Script. The variable that is getting lost is not being passed to the script it is a URL Variable from the referring page. Flow is as follows on the index.cfm I as the user for a document number, using the document numbe I take them to page 2 (add workflow), when I am validating fields on the add workflow page I lose the referring document number. function checkrequired(which) {   var pass=true;   for (i=0;i<which.length;i++) {     var tempobj=which.elements[i];     if (tempobj.name.substring(0,8)=="required") {       if (((tempobj.type=="text"||tempobj.type=="textarea")&&           tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&           tempobj.selectedIndex==0)) {         pass=false;         break;       }     }   }   if (!pass) {     shortFieldName=tempobj.name.substring(8,30).toUpperCase();     alert("The "+shortFieldName+" field is a required field.");     return false;   } else {   return true;   } }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Billy Cox
11/19/2007 11:18 AM

Perhaps you could store your url value to a hidden form field which could then be manipulated using javascript? ----- Excess quoted text cut - see Original Post for more ----- Here is the validation Script. The variable that is getting lost is not being passed to the script it is a URL Variable from the referring page. Flow is as follows on the index.cfm I as the user for a document number, using the document numbe I take them to page 2 (add workflow), when I am validating fields on the add workflow page I lose the referring document number. function checkrequired(which) {   var pass=true;   for (i=0;i<which.length;i++) {     var tempobj=which.elements[i];     if (tempobj.name.substring(0,8)=="required") {       if (((tempobj.type=="text"||tempobj.type=="textarea")&&           tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&           tempobj.selectedIndex==0)) {         pass=false;         break;       }     }   }   if (!pass) {     shortFieldName=tempobj.name.substring(8,30).toUpperCase();     alert("The "+shortFieldName+" field is a required field.");     return false;   } else {   return true;   } }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/19/2007 12:07 PM

Ok, now can you show the <FORM tag, and the code that triggers checkrequired() ? Pretty hard to find problems with your code if you don't show your code. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
jennifer fiers
11/19/2007 12:57 PM

----- Excess quoted text cut - see Original Post for more ----- Thank you all for being so patient with me. Here is the form tag <form name="bcr_add" onSubmit="return checkrequired(this)" action="bcra_request_confirm.cfm"> I have also tried <form name="bcr_add" onSubmit="return checkrequired(this)"> and <form name="bcr_add" onSubmit="return checkrequired(this)" action=""> With the same results.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
11/19/2007 01:33 PM

Ok, first, you should use METHOD="post" in your form. instead of the default value "get", and in the action template, look for values in the form scope instead of url. Another problem I see: If I understand well, you are checking that any required select area has not its selectedIndex==0 but selectedIndex == 0 means the first element is selected. If no element is selected, you will have selectedIndex < 0; Thus, your code actually lets unselected select area pass the test. In this case, the name of the field is not passed to the action template, either in GET or in POST mode. -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks.


<< Previous Thread Today's Threads Next Thread >>

Search javascript

May 18, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference