Skip to main content
Inspiring
July 25, 2009
Answered

Passing record id during onClick while also submitting the form

  • July 25, 2009
  • 1 reply
  • 958 views

I'm displaying data in two different tables. All of the data is static except for a status field which is also the field that determines what table the data is displayed in. Inside of form tags I am using a cfoutput tag to loop through the records for each table. The status record is in a cfinput with a type of radio button to set the status. I can submit the form using the onClick event of the radio button but I'm unsure how to pass the record id of the record that will need the status field to be updated on my action page. Is it possible to pass this record id along using javascript and then read that it on the action page to pass along to my sql? I planned to send the form back to the same page so that toggling the radio button would move the record to the other table. I wanted to avoid using a submit button and have the change in values of the status field move the record to the "closed" status table or vice versa.

    This topic has been closed for replies.
    Correct answer Leonard_B

    Greetings,

    Have you tried adding the code below the end of your action line

    ?record_id=#URLEncodedFormat(record_id)#

    Example:

    onClick="this.form.action='path_to_page.cfm?record_id=#URLEncodedFormat(record_id)#';this.form.submit()"

    If I understand what it is you are trying to do, I setup a sample and tried the above "Example" code and it

    passed a record id to the designated page without any issues arising.

    Leonard

    1 reply

    Leonard_BCorrect answer
    Inspiring
    August 21, 2009

    Greetings,

    Have you tried adding the code below the end of your action line

    ?record_id=#URLEncodedFormat(record_id)#

    Example:

    onClick="this.form.action='path_to_page.cfm?record_id=#URLEncodedFormat(record_id)#';this.form.submit()"

    If I understand what it is you are trying to do, I setup a sample and tried the above "Example" code and it

    passed a record id to the designated page without any issues arising.

    Leonard

    Inspiring
    August 21, 2009

    Hi Lenorad,

    I ended up building my forms a different way in this situation but your answer was exactly what I was looking for at the time. I was unaware that I could pass the action url with a variable on it as part of the onClick event. Thanks for showing me this.

    -John