Cfquery within javascript

hi,
I am trying to do the following:
I wrote a cfquery within javascript function as below:
<script language="javascript1.2" type="text/javascript">
<cfquery name="query1 datasource="abc">
</cfquery>
<cfif query1.recordcount neq "0">
    <cfoutput query = "query1">
       <cfquery name="query2 datasource="abc">
  select * from table1 where name=#query1.name#
       </cfquery>
    </cfoutput>
     alert(<cfoutput>#query2.RecordCount#</cfoutput>);
</cfif>
</script>
The alert value is 1 but the debugging section shows 0, and 0 is the correct value. is there something wrong that I am doing.
If so can you please point out...

The problem comes from how CF and JS work: Coldfusion is a "Server Side" language while Javascript is "Client Side". This means the server runs through all the CF code in your page and sends the finished product on to the user's browser which THEN starts handling the Javascript.
I'm not sure of your intended outcome ... do you want a series of "alerts" as soon as the page loads? If you are using the alert for debugging (just to see what is being returned, you can replace it with <p> tags and you will see the output on screen. Try this:
<cfif query1.recordcount neq "0">
     <cfoutput query = "query1">
          <cfquery name="query2 datasource="abc">
          select * from table1 where name=#query1.name#
          </cfquery>
          <p>#query2.RecordCount#</p>
     </cfoutput>
</cfif>
2 more notes:
you don't the inner "cfoutput" around you record output if you are going to use cfoutpu to loop over your query.
the output line needs to be INSIDE the loop or you'll only output the last iteration.

Similar Messages

  • Database connection(select ,insert query) within javascript function

    Hi ,
    How to write the database connection(insert,delete or select query) within javascript function.Is it possible.Anyone can you help me
    than you

    Hi ,
    How to write the database connection(insert,delete
    ete or select query) within javascript function.Is it
    possible.No

  • Cfquery to javascript array to .js file

    Hi guys,
    I've got a small problem out there:
    have cities table in the database therefore pulling out everything using cfquery .
    <cfquery name="get_city" datasource="IGES">
    SELECT *
    FROM cities
    ORDER BY City ASC
    </cfquery>
    Now all these city names from database needs to be passed to .js file in some sort of array
    <script type="text/javascript" src="../jscripts/add_school.js"></script>
    ^^^^^^^^that's the file all the javascript is in
    Is there any way to pass an array made from cfquery to javascript file where it can be used to populate listbox.
    cheers,
    Simon

    Hi Ian,
    Thanks a lot, that toScript() stuff did the job properly.
    cheers,
    Simon
    "learning every day"

  • How to insert Javascript within Javascript ?

    I have a simple problem.
    I want to insert Javascript within Javascript ???
    Seems weird !!!
    Here's the scenario :
    I have created a JSP in which I have a function that Submits the main form in the main window.
    Here's the function :
    function SubmitContent()
    document.f1.method='post';
    document.f1.action='http://localhost:8080/examples/sherbir/texteditor2/page2.jsp';
    document.f1.submit();
    and here's the form description :
    <form name='f1'>
    But before that, on clicking the submit button in the main window, I am opening a child window to perform a few operations as follows :
    <input type="button" name="bttn_preview" value="Preview" onClick="javascript:SeePreview()">
    Here's the SeePreview() function which opens the child window:
    function SeePreview()
    var mywin=window.open("","","menubar=no,toolbar=no,scrollbars=yes,width=800,height=450");
    mywin.moveTo(0,50);
    mywin.document.write('<input type=button value="Make more changes"
    onClick=javascript:window.close()>');
    mywin.document.write('<input type="submit" name="child_bttn_sub" value="Proceed" onClick=self.close(); self.opener.SubmitContent();>');
    The child window in turn has a submit button as defined above.
    On clicking this button, I want the child window to close and hence submit the parent form also.
    It's not happening !!
    I even tried changing the order of the two statements in the OnClick event of the submit button in the child window.
    I also tried self.opener.document.forms[0].submit()
    None works.
    Where's the problem ??
    How do I remedy the situation ?
    Please Help.

    Not satisfiedAnd you won't be till you ask the right people for an answer. This is Java, and JavaServer Pages (JSP), not Javascript. If you go to a Javascript forum you will have a better chance of finding people who know more Javascript. Makes sense, doesn't it?

  • Accessing java objects from within javascript

    Hello,
    Anyone with an idea of a useful toolkit for accessing java objects from within javascript will be much appreciated.
    Thanks in advance,
    Antana.

    What do you mean by accessing Java objects? Do you mean interacting with an applet via JavaScript? Something else?

  • Cfoutput within javascript

    Just trying to install the google ecom tracking code supplied
    by google. It
    does some nice things like the actual ROI depending on pay
    per click word
    chosen.
    Ive never had to output cold fusion varibles beofre within
    javascript. Do i
    need to use use the toscript tag or would the code below
    work? Any help
    appreciated.
    <!----google e-com tracking--------->
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-xxxxxx-1");
    pageTracker._trackPageview();
    <!------Output query results into javascript-------->
    <cfoutput query="order2">
    pageTracker._addTrans(
    "#i_orderid#", // Order ID
    "#d_grandtotal#" // Total
    </cfoutput>
    // add item might be called for every item in the shopping
    cart
    // where your ecommerce engine loops through each item in
    the cart and
    // prints out _addItem for each
    <cfoutput query="lines" >
    pageTracker._addItem(
    "#lines.i_orderid#", // order ID
    "#lines.s_partno#", // SKU/code - required
    "#lines.d_price#", // unit price - required
    "#lines.i_quantity#" // quantity - required
    </cfoutput>
    pageTracker._trackTrans();
    </script>

    Hi Dan
    i did run the code and a part of it works. a transcation
    with google gets
    recorded however all the other parameters are not recorded. I
    suspect this
    is due to my syntax.
    Im a hack and dont know too much about js arrays but from
    what ive been able
    to find on the web, would it look something like this?
    Should they be js variables do you think?
    <!----google e-com tracking--------->
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-xxxxxx-1");
    pageTracker._trackPageview();
    <!------Output query results into javascript-------->
    <cfoutput query="order2">
    pageTracker._addTrans(
    var #toScript(i_orderid, "OrderID")#; // Order ID
    var #toScript(d_grandtotal, "Total")#; // Total
    </cfoutput>
    "Dan Bracuk" <[email protected]> wrote in
    message
    news:g9oiia$t5s$[email protected]..
    > If you want to know if the code works, run it.
    >
    > There are a couple of ways to mix cold fusion variables
    with javascript.
    > One
    > is the to_script tag. The other is to surround the
    entire javascript
    > block
    > with cfoutput.
    >
    > In your case, to_script seems like a better approach.
    Make each query
    > column
    > a js array.
    >

  • Use netui tags within javascript function

    Is there anyway to use netui tags within a javascript function? I am trying to create a onChange event handler for a netui:select tag that will call a javascript function which will execute a few netui callMethod tags. The problem is that if the netui tags are embedded within a javascript function they are not translated into javascript. Is there some kind of function that I can wrap the embedded netui tags with so that they will be translated into javascript at runtime? Thanks.

    Hi,
    I am trying to embed JSP code within javascript
    t function, so that it can be called when the user
    leaves the page. No,you can't.
    JSP files are complied on server side while the javascript is the clint side code.
    if you really want to call the functio when the user leaves the page, you can call a function runs on the server side to set the session.
    regards

  • NSDP from within javascript?

    Hi,
    I have noted that it has been suggested that utilisation of a Non Spatial Data Provider(NSDP) could actually speed up dynamic theme FOI rendering as the spatial column is not needed in the join towards the BaseMap.
    Can that be done from within javascript? Any examples? Could it speed up rendering even though basemap as well as foi themes are located in the same database?
    I'm experiencing somewhat poor performance using dynamic theme FOI rendering via jdbc_query.
    10.1.3.1
    Best regards Jesper

    Can you provide more details on the query and the performance issue you're experiencing.
    I'm not sure how using NSDP will speed things up. The spatial data still has to be queried and retrieved in order to render it.
    Jayant

  • Call Process within javascript

    NEWBIE QUESTION:: If possible, how can you call a page process from within a javascript code segment.
    I have a for loop that needs to call a process.

    AJAX is part of your browser.. APEX supports it.. Maybe you should do some reading on the subject...
    Thank you,
    Tony Miller
    Webster, TX
    What if you really were stalking a paranoid schizophrenic... Would they know?
    If this question is answered, please mark the thread as closed and assign points where earned..

  • HELP: Possible to nest %=expression% within javascript code?

    Hi, I'm working on an application where I need to use dynamic JSP variables in javascript, as shown below
    onclick="jsFunc(this.form, '<=myClass.getSpecialString()%>');">(Te code is originally within a button tag)
    This will not work, any ideas why? If I alert the second javascript parameter in the jsFunc javascript function, I'll get <=myClass.getSpecialString%> written out in the message box instead of the value returned by myClass.getSpecialString().
    This means that the parser apparently does not first evaluate the JSP <%%> tags as one would expect...
    How can I provide JSP values in a javascript function as shown??
    Very thanful for any answers on this one!!
    Best Regards/
    AC

    As you see, there is some struts involved, however,it
    does not affect the main problem here...
    <html:button property="page"styleClass="form"
    onclick="jsFunc('<%=myClass.getString()%>');">
    <bean:message
    ean:message
    key="regularcustomer.ord.bulkorder.addBtn"/>
    </html:button>
    <SCRIPT LANGUAGE="JavaScript">
    function sFunc(test){
    alert(test);
    </SCRIPT>
    The problem is that the onclick attribute of the
    button tag can support run time JSP expressions, ONLY
    if the entire attribute is a JSP expression. If you
    just had this...
    onclick="<%=myClass.getString()%>", it would work.You would have to wrap the jsFunc() call inside of a Java String, along with the myClass.getString() String, for it to work correctly.

  • CFquery to javaScript Array to Listbox

    Help!
    Here's what I've got so far:
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <cfquery datasource="ERMRiskMgmt" name="DelegateList">
    SELECT CoordFirst + ' ' + CoordLast AS 'AvailDelegate',
    CoordID
    FROM dbo.ERMCoordinators
    ORDER BY CoordLast
    </cfquery>
    <script language="javascript" >
    function addOption(selectbox,text,value )
    var optn = document.createElement("option");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
    function addOption_list(selectbox)
    var nator = new Array(<cfoutput
    query="DelegateList">"#AvailDelegate#",</cfoutput>"");
    for (var i=0; i < nator.length;++i)
    addOption(document.drop_list.DelegateSelect, nator
    , <cfoutput
    query="DelegateList">#CoordID#</cfoutput>);
    </script>
    <title>Untitled Document</title>
    </head>
    <body onload="addOption_list()";>
    <form name="drop_list" action="" method="post" >
    <select name="DelegateSelect">
    <option value="" ></option>
    </select>
    </form>
    </body>
    </html>
    I realize those 2 queries arent 'associated' yet - still
    workin on that - Help! Ty!

    End Result, Display a Listbox with the Coordinator Fullnames,
    having the value
    of that Coordinators ID.
    I'm using the Array Because the 'form' is inside a CFOUTPUT
    for a list of
    reports, not directly related to this CFOUTPUT of coordinator
    Names. Its there
    to allow for the delegation of reports to members of the
    'Coordinator Table' .
    I hope that claifies...?

  • How to Access Database Table Column Data within Javascript in ApEx

    Hi,
    I have a column in a database table that contains several urls and I was wondering what is the best way to get these urls from the database table into a javascript function.
    Example code of how to approach this would be much appreciated.
    Thanks.
    Tony.

    Tony,
    See this simple example:
    http://apex.oracle.com/pls/otn/f?p=31517:80
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Database check within javascript

    I have javascript validation code, but some of it is depended
    on database results. So, I just want to do a simple database check
    and then run javascript code based on the query results. For
    example:
    <script language="JavaScript">
    function validate_form ( )
    valid = true;
    <!-- <cfif not compareNoCase(Topdata.demil_cd,'F')>
    //-->
    if ( document.test.field1.value == "Test" )
    alert ( "Blah, blah blah." );
    valid = false;
    <!-- <cfelse> //-->
    if ( document.test.field2.value == "Test2" )
    alert ( "Blah, blah blah." );
    valid = false;
    <!-- <cfif> //-->
    return valid;
    </script>

    Run your query before your opening script tag. Use the
    toScript function to bring your database results into js.

  • Accessing Instance variables from within javascript

    Is it possible to access Instance variables of a JSP using
    javascript? If so, an example would be very much appreciated.
    LaMont

    <script language="JavaScript">
    var scriptVar = "<%= jspVar %>";
    </script>

  • Call page process within Javascript

    Hey guys! Just shortly after working out my conditional Javascript dialog function I stumbled upon another little problem that is as follows:
    I need to call a page process from the Javascript function "dialogwarning" when the save button of a jquery dialog is clicked.
    The Update action works already but the pl/sql process is not carried out.
    Actually it cannot be that difficult...
    Can you please give me a hint how to accomplish it? Until now I've only seen threads were javascipt was called in an pl/sql process - not vice versa.
    Here's my code for the dialog:
    $(function(){
      $("#dialogwarning").dialog({
        autoOpen: false,
        bgiframe: true,
         modal: true,
            width: 400,
            minWidth: 400,
            resizable: true,
         buttons:{
           Save: function(){
              doSubmit('UPDATE','APPLICATION_PROCESS=proc_reset_mx_results');
          Exit: function(){
             $(this).dialog('close');
    </script>Any help is appreciated!
    Regards,
    Sebastian

    Well Dirk, thanks for your feedback.
    Option number 2 does not work for me since the "UPDATE" raised by the javascript function saves something to a table a and is supposed to launch a process that deletes from another table b. The javascript function in turn is already conditional to be raised only when some criteria match and a delete action is neccessary.
    In short words, option 1 would cause the launch of the delete procedure whenever the update process is called.
    Thus, I just created an application process proc_reset_mx_results that is of type after page submission:
    begin
    Delete from tbl_matrix_intermediate_result
    where str_lrt_class = :p231_str_lrt
    and lng_gebiet      = :p231_str_gebiet
    and int_be          = :p231_bewertungseinheit
    and eval_type       in (7,8);
    end;My problem - it doesn't work as it should. The dialog opens, I click the save button and in turn the update action is carried out. However, nothing is deleted from table b i.e. tbl_matrix_intermediate_result!
    Regards,
    Sebastian
    Wow, thanks for all your interest!
    @ roel
    It's a custom pl/sql anonymous block that is supposed to be called using the button of that jquery dialog. The dialog itself is only raised when a condition is met.
    The background info:
    -A user enters data that is stored in table a
    -The user goes to an evaluation module where the input values are weigthed and evaluated in an extensive stored procedure.
    -The user has the option to override the automatically calculated result by entering custom results.
    -Both result sets (automatic and custom values) are saved in tbl_matrix_intermediate_results.
    Here it comes:
    Only if the user modifies the input data after the evulation has been performed, then the message-box should be displayed and if the user agrees, all previous results should be deleted.
    I believe a trigger is not the proper tool for my purpose.
    I hope you can understand my point and problem now?
    Edited by: skahlert on 01.03.2010 14:20

Maybe you are looking for