Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass javascript variable to coldfusion?

Status
Not open for further replies.

menu

Technical User
Apr 25, 2001
24
0
0
AE
Hi,

I need to know whether a javascript variable can be passed to coldfusion.I have a drop down menu populated by the database on left frame and a deletebutton on the right frame .When user selects one from the drop down and clicks delete , a confirmation dialog box appears on the screen asking whether the user wants the item to be deleted ,when clicked o.k, it performs a JSfunction to update the dropdown with the curdata.Before reloading itself with the updated info. it has to update the DB.The problem here is the selected name is passed to javascript but i'm not able to get it back to coldfusion for db updation.I sthere a way to do it? Please help.It's urgent.Any help is appreciated.

Thanks,
Jane.
 
Why don't you just code the entire application in ColdFusion--it seems like there would be no problem creating a solution to delete a drop-down list option and then reload a frame. When the page reloads and receives the drop-down options from the database, the deleted option will be gone (and thus will not appear).

Make the form submit to a CF template with the following code:

<CFQUERY NAME=NAME DATASOURCE=YOURDSN>
DELETE FROM TableName WHERE Option = #Form.Option#
</CFQUERY>
<CFLOCATION URL=&quot;URL FOR LEFT FRAME&quot;>

The code for the JavaScript confirmation popup before the form is posted to the above template is (surrounded by script tags):

confirm (&quot;Are you sure?&quot;) [sig]<p>Ryan ;-]<br>[/sig]
 
Hi,

U can do that if u pass ur parameter thru the URL
Here is some code for u:

<--JS file-->
Function confirm(form){
//code popup ur confirm window here. if confirm
//is &quot;Yes&quot; then do this
mypassingvariable=form.myselectedmenu.value
window.location.href = &quot;mydeletingcfmfile.cfm?myfieldtobeDeleted=&quot;+mypassingvariable
//else do this ....
}
<-- mydeletingcfmfile.cfm-->
<cfquery name=&quot;deletestuff&quot; datasource=&quot;mydb&quot;>
<!-- ur code for deleting stuff goes here-->
</cfquery>

*note: after u delete ur stuff from ur database, ur left frame still the same unless u have to call the newest cfm file
I hope this help. Let me know if u have any problem

[sig]<p>GH ((-:<br><a href=mailto:giahan@hotmail.com>giahan@hotmail.com</a><br>(-:[/sig]
 
giahan,

How do I do this same thing passing url variables instead of form vars? [sig][/sig]
 
EricE,

U can pass form/url vars by passing the parameters thru funtion delaration
<--JS file --->
Function myPassingFunction(form, urlvar1, urlvar2,....){
//then ur code goes here
window.location.href = &quot;myFile.cfm?myvar1=&quot;+urlvar1+&quot;...&quot;+urlvar2+&quot;...&quot;
}

I hope this help [sig]<p>GH<br>[/sig]
 
The reason most Javascript variables will not pass to a CF function is the processing sequence. Remember, ColdFusion is actually generating the HTML on its server, then passing it to the browser.

On the client machine, if the browser is set to allow it, Javascript is executed.

That is also why you can pass a variable thru as a (hidden) form variable or URL variable. It is being sent to a new page!

Paul [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top