Skip to main content
Known Participant
January 14, 2010
Question

Pass hidden value through a form

  • January 14, 2010
  • 2 replies
  • 2438 views

Hi.  I'm trying to create a registration form in which users select an organization from a drop down list that is populated from a db table.  All I want the user to see is the origanization's name, but there is also an ID number for each organization in the table.  Is there a way I can submit the ID number for the origanization the user chooses as a hidden field?  I feel like it should be fairly simple, but I can't wrap my brain around it.

Thanks for any help!

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    January 14, 2010
    I feel like it should be fairly simple

    You feel right. It is. Here is an example

    <script type="text/javascript">
    function hideOrgID(){
        document.forms[0].org_id_hidden.value=document.forms[0].org_id.value;
    }
    </script>

    <form>
    <select name="org_id" onchange="hideOrgID()">
    <option value="id0" selected="true">Select organization</option><!--- default choice: required --->
    <option value="id1">Org 1</option>
    <option value="id2">Org 2</option>

    <option value="id3">Org 3</option>
    </select>
    <input type="hidden" name="org_id_hidden">
    </form>

    BKBK
    Community Expert
    Community Expert
    January 14, 2010

    Realize it would have been better given as test code. So here goes:

    <script type="text/javascript">
    function hideOrgID(){
    document.forms[0].org_id_hidden.value=document.forms[0].org_id.value;
    }
    </script>

    <cfif isdefined("form.sbmt")>
    <cfdump var="#form#">
    </cfif>


    <cfoutput><form action="#cgi.SCRIPT_NAME#" method="post"></cfoutput>
    <select name="org_id" onchange="hideOrgID()">
    <option value="id0" selected="true">Select organization</option>
    <option value="id1">Org 1</option>
    <option value="id2">Org 2</option>
    <option value="id3">Org 3</option>
    </select>
    <input type="hidden" name="org_id_hidden">
    <input type="submit" name="sbmt" value="Send">
    </form>

    Owainnorth
    Inspiring
    January 14, 2010

    Am I missing something here? I don't see how that function could hide a value. Anyone viewing the source can still look at the values in the Select list.

    If you're passing an ID to someone's browser and back then you cannot hide it, short of encrypting it. Either it's a small internal system where you trust the users not to hack around with your data, or you need a different solution.

    O.

    January 14, 2010

    In your SELECT drop down show the organization on the page but have the VALUE part of the OPTION be the org ID. Is this what you're shooting for?

    <select name="org_id">

    <option value="0001">ACME Welding</option>

    <option value="0002">ACME Parts</option>

    </select>

    straffenpAuthor
    Known Participant
    January 14, 2010

    Thanks for the reply.  I think this is moving in the right direction.  I think the values need to be separate though because I need to store the org_name and org_id in separate fields in the registration db table.  Any ideas?

    Inspiring
    January 14, 2010

    Why do you need to store both the id and the name in your registration table? 

    If you absolutely must, send them both as a list as the value of your select control and separate the list on your action page.