Skip to main content
Participant
August 2, 2007
Question

Loop and set variables to pass

  • August 2, 2007
  • 2 replies
  • 808 views
Hello All,

In the form I loop over a query and create a checkbox for each batch id, but the checkbox name is of course the same for each.

Then I have a button that does on "onclick" and calls my function.

<script language="javascript">
function thisBatch(url)
{
//alert(url);
location.href = url;
}
</script>

Here's how I've got the checkbox set:

<input type="checkbox" name="status" value="#batch_id#">

Then the "Submit" button:

<input type="submit" name="submitBatch" value="BATCH REQUESTS" onClick="thisBatch('#client.root#/batch_application.cfm?batch_ticket=1'); return false" />

I've tried to add document.forms.status.value to the "onClick" function, as well as setting a "var" within the javascript. I'm just not able to grab multiple checkbox values and pass them. Also, I'm not sure why, but this section I'm developing in is Fusebox 4 and my debugging doesn't even show any form variables being passed? So, it appears as if I need to set it in the URL to pass correctly.

If anyone has a really good example, I would greatly aprreciate it!

Kiamber
    This topic has been closed for replies.

    2 replies

    Inspiring
    August 2, 2007
    >> my debugging doesn't even show any form variables being passed
    Probably because thisBatch() is changing the window location not submitting the form.

    Why do you need the thisBatch() function at all? You can set the action page in your form declaration

    <form actionPage="#client.root#/batch_application.cfm" method="post" ... >

    If needed, you can store the "batch_ticket" value in a hidden form field.

    kiamberAuthor
    Participant
    August 3, 2007
    I need to pass every checkbox value. This would be dynamic, so I need to use the javascript to pass it in the url.

    I did try using status#batch_id# as the name of the checkbox, but now I'm not sure how to pass and set that value in the thisBatch function?

    Thanks for all the input so far!
    Inspiring
    August 3, 2007
    > and my debugging doesn't even show any form variables being passed
    If you're passing values in the url, then they wouldn't show up as FORM variables they will be in the URL scope. Is there a reason you have to pass the form field values in the url instead of using <form method="post" ...>?

    >I need to pass every checkbox value. This would be dynamic, so I need to use
    >the javascript to pass it in the url.

    I still don't see why you need javascript. If the form uses method="get" the form field values will automatically be passed in the url on submit. If mutliple boxes are checked, the selected values will be passed as a comma delimited list like #url.batch_id# = 22,9,46,99. If nothing was checked "url.batch_id" won't exist.

    Of course there are limitations on the max length of a url. That's one reason people tend to use method="post" for submitting form data instead of method="get". But it all depends on what you're trying to do.


    existdissolve
    Inspiring
    August 2, 2007
    Have you tried giving each checkbox a unique name?

    Something like name="status#batch_id#" ?
    kiamberAuthor
    Participant
    August 2, 2007
    I'll try that now, but I'm still not sure how to pass those since the loop dynamically creates each checkbox based on a users individual search criteria. It still won't show me the form variables in debugging? :0( Thanks for the input! :0)

    Kiamber