|
Mailing Lists
|
Home /
Groups /
Javascript
ColdFusion losing Variable value after calling JavaScript
>>How can I keep this value when the javascript returns? Any help wouldClaude Schneegans 11/19/07 10:19 A >>>How can I keep this value when the javascript returns? Any help wouldjennifer fiers 11/19/07 11:04 A Perhaps you could store your url value to a hidden form field which couldBilly Cox 11/19/07 11:18 A Ok, now can you show the <FORM tag, and the code that triggersClaude Schneegans 11/19/07 12:07 P >Ok, now can you show the <FORM tag, and the code that triggersjennifer fiers 11/19/07 12:57 P Ok,Claude Schneegans 11/19/07 01:33 P 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. >>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. ----- 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; } } 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; } } 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. ----- 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. 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.
|
May 18, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||