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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute SQL statement from JS function?

Status
Not open for further replies.

fdarkness

Programmer
Joined
Feb 17, 2006
Messages
110
Location
CA
I have an application built in ColdFusion. Right now, it's displaying rows in a table, with one column having a drop down option box.

I'd like to build a function that INSERTs or UPDATEs a SQL database with the contents of the row when the contents of the drop down box are changed (onChange) function.

How the heck can I do this? Do I need to use JavaScript for the SQL and if so, how? Or am I making this more complicated than it needs to be?
 
You'll need to either:

1) submit the page to a server side language to perform the SQL

or

2) use AJAX to load a new page to perform the SQL

Either method will require some form of server side language: ASP, PHP, Cold Fusion, JSP, etc.....

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Yes, I'm aware that it'll need a server-side language... As I said, the page is written in ASP. I think I'm missing how to actually write the function for the onChange event with SQL commands in it and then having CF execute it.

I might just be totally braindead since A) it's Friday, and B) I've been working on this application all week and I'm completely stressed out by it. :)
 
As I said, the page is written in ASP

Actually you said Cold Fusion, and I completely skipped over it.... sorry.

You'd really probably be better off asking how to perform the select statement in the Cold Fusion forum, but as far as getting the <select> box to execute the submission:

Code:
<form id="whatever">
   <select name="dropdown" [!]onchange="document.forms['whatever'].submit()"[/!]>
      <option value="1">1</option>
      <option value="2">2</option>
   </select>
</form>

-kaht

[small] <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
[banghead] [small](He's back)[/small]
 
Oh damn. That's how brain dead I am. Yes, ColdFusion. Sorry. I'd *rather* be writing it in ASP, but that's neither here nor there. :)

I'll run over to the CF forum and see if there's any ideas there. Thanks. :)
 
how about you make an iFrame, and either set its width and height to 0 (easy way, but doesnt work properly in firefox, if I recall correctly) or put it in a div offstage or something, and basically submit the form to the hidden iFrame onClick.

I did a quick test

<form name="form1" method="post" target="iView" action="dosqlstuff.cfm">

<!-- your form code here-->

</form>
<iframe name="iView" width="0" height="0"></iframe>

I hope that helps

James
 
James: I'll give that a try when I get into work on Monday, if I can't figure another way around it (or I'll give it a shot just for the helluvit). And I don't have to worry about cross-browser issues... work requirement / standard is IE only, with slaps going around to anyone who installs "non-standard / non-tested" software.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top