www.webdeveloper.com
Results 1 to 10 of 10

Thread: Return command in Javascript

  1. #1
    Join Date
    Jan 2003
    Posts
    19

    Return command in Javascript

    We are writing a javascript where we are trying to pass an element name back to the server side. Here is what we are tring to do.
    <SCRIPT LANGUAGE= "Javascript">
    function DefForm(str) {
    var ele=document.Form.elements;
    var len=ele.length;
    for (i=0;i<len;i++) {
    if (ele[i].name = str)
    {return ele[i].name}}}
    </SCRIPT>


    In the program we are doing
    <cfif IsDefined("return DefForm('quoteStat#ctr#')") and other stuff. Will this retrun the element name back to the IsDefined function? We are using ColdFusion if this helps.

  2. #2
    Join Date
    Dec 2002
    Location
    Switzerland
    Posts
    428
    Without sending back to the server, it doesn't, cause javascript works on the ClientSide and not ServerSide.


    Swon

  3. #3
    Join Date
    Jan 2003
    Posts
    19
    How do we get it to send back to the server? I have seen examples of other peoples problems and they are doing a return true or return false to the html code.

  4. #4
    Join Date
    Dec 2002
    Location
    Switzerland
    Posts
    428
    You can do it this way:

    <SCRIPT LANGUAGE= "Javascript">
    function DefForm(str) {
    var ele=document.Form.elements;
    var len=ele.length;
    for (i=0;i<len;i++) {
    if (ele[i].name = str)
    {
    window.location.href= self.location.href+"ele="+str;
    }
    }
    }
    </SCRIPT>


    Swon

  5. #5
    Join Date
    Dec 2002
    Location
    Switzerland
    Posts
    428
    By the way, you should use ele[i].name == str instead of ele[i].name = str


    Swon

  6. #6
    Join Date
    Jan 2003
    Posts
    19
    Swon,
    Thanks for the help you given us so far. The item about the == was a typo on my part. I already had it that way in the program. What do I do about the portion of code in the program where it reads <cfif IsDefined("return DefForm('quoteStat#ctr#')")... should I take out the return portion and it will read then <cfif IsDefined("DefForm('quoteStat#ctr#')")?

  7. #7
    Join Date
    Dec 2002
    Location
    Switzerland
    Posts
    428
    I don't know exactly what you wanna do, but if you only need the value of the returned variable 'ele' you need only to get the variable with the get method, so I think there's no need for <cfif isDefined> one.


    Swon

  8. #8
    Join Date
    Jan 2003
    Posts
    161
    The Javascript code is quite often intertwined with HTML code.
    The return code from a function will tell the HTML construct what to do.
    For example, a form might have an onsubmit even handler. The JS event handler will return true or false and based on this value the form will/will not get submitted.
    So, the return value can be used only on the client side.

    Cheers,
    Dan

  9. #9
    Join Date
    Jan 2003
    Posts
    19
    An explanation od what we are tring to accomplish follows. We have radio buttons for selecting one of two choices. We have the ability to have these choices for one or more items, such as 1 yes no
    2 yes no
    3 yes no where yes and no are the radio buttons.

    We have to know which row is yes and which one is no. Coldfusion will not allow us to concatenate a counter to the element such as form.quotestat#ctr# where ctr is the counter of rows. We came up with using Javascript to solve this problem. Each row would equate to quoteStat1, quoteStat2, quoteStat3. We need to know that the element exists which is where the IsDefined procedure comes in. <cfif> is an if statment. So we are tring to say if the form element exists and yes is selected do this or if no is selected do that.

  10. #10
    Join Date
    Jan 2003
    Posts
    19

    Smile

    There is a way in ColdFusion to test for a element with a counter at the end. We are using the Evaluate command to do this. Thanks for all your help in this matter.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles