Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Unanswered: call function javascript from ASP, but with value to return

    Hello

    I need someone to help me to be able to continue the development of a page in ASP code (not .NET)

    I have a function in javascript (it's run fine), but I need call this function from ASP code by passing the value of a text variable retrieved from a database, for the function in javscript and manipulate the text and return this text with some change (CR replace with <br />, URL with anchor, ...)

    I "only" need something like this (obviously does not work!)

    <script>
    function functionJS(value) {
    //javascript code fot text manipulation
    }
    </script>
    ...
    <body>
    <% variable=functionJS(text); %>
    <p><%= variable %></p>
    </body>

    If anyone can help me I would be grateful.

    Thanks

  2. #2
    Join Date
    May 2009
    Location
    India
    Posts
    66
    I think what you need is:
    (1) Change the javascript code to write the revised content to a hidden field on the form.
    (2) Read the hidden field through the lhs=request("hidden_field")

    OK

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Thank-you AnanthaP for help me.

    It's not possible because I have a undefined number of contents recovered from data base, and I don't could generate a undefined number of hidden fields for make the conversion with javascript function.

    Fortunately I found a function for implementing in ASP code for make the same function than in javavascript and I call this new function for convert the text fields recover from data base.

    Thanks.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    can you give more details around what you are actually trying to achieve? This sounds like one of those problems where the solution is going to be quite different from the original approach taken.

    What are you doing in your javascript function that can't be done in server side code?

    If it has to be client side code then what does the output really look like?

    One of your options might be to do something like....

    Code:
    <script>
    function functionJS(value) {
        //javascript code fot text manipulation
        return "some changed text"
    }
    
    function reformat() {
        var contentDiv = document.getElementById("content");
        var hiddenValue= document.getElementById("serverText");
        contentDiv.innerText = reformat(hiddenValue.value);
    }
    </script>
    ...
    <body onload="reformat();">
    <input type="hidden" id="serverText" value="<%variable%>">
    <% variable=functionJS(text); %>
    <div id"content"></div>
    </body>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •