#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0

    Form variable undefined


    Hi,
    I am new to coldfusion and i am trying out a sample cfm page. I have a dropdown where in i have 3 values say 1,2,3. Onchange of the dropdown, i need to set a hidden variable with the changed dropdown value. I am able to alert the dropdown value in javascript but not able to assign that value to the hidden variable. Please assist me.
    My Sample code is as below:

    <script language="javascript">
    function loadHiddenvar()
    {
    alert("inside fn");
    var ddVal=document.getElementById('dd1').value;
    document.test.h1.value=ddVal;
    alert(document.test.h1.value);
    }
    </script>
    <form name="test" id="test">
    DD1: <select name="dd1" id="dd1" onchange="loadHiddenvar();">
    <option value=1>first</option>
    <option value=2>second</option>
    <option value=3>third</option>
    </select>
    <input type="hidden" name="h1" id="h1" value= "">
    <cfif isdefined("form.h1")>
    {
    <cfoutput>Hidden var is #FORM.h1#</cfoutput>
    }
    Its always giving me variable h1 undefined.
    I tried assigning this to a new variable and putting that as the hidden variable value. But that also didn't work out
    <cfset a="#form.h1#">
    <input type="hidden" name="h1" id="h1" value= #a#>
    What is that I am missng here?

    Thanks in advance,
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    I'm here to help but for something like this please at least do a Google search before you post.

    http://stackoverflow.com/questions/1...ing-javascript
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0
    Hi Kiteless,
    Thanks for the reply. I think you dint get my question. I was able to get the value of dropdown selected. But in the coldfusion I was not able to assign that value to my hidden variable.

    <input type="hidden" name="h1" id="h1" value= "">
    <cfif isdefined("form.h1")>
    {
    <cfoutput>Hidden var is #FORM.h1#</cfoutput>
    }

    Thank you
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,243
    Rep Power
    967
    Sorry, I thought you were asking how to actually get the value from the select box. Changing the value on the page won't affect the CFML because the CFML was already executed on the server. You can't pass values from JavaScript to CF this way. JavaScript runs in the browser, and CFML runs on the server. The only way to make the server aware of the change and have your cfif execute again is to initiate another HTTP request by submitting the form.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    15
    Rep Power
    0
    Hey Thanks...actually yea i the value was correctly set to the hidden variable. i was able to retrieve the value in the next page

    Thanks for your patience and help

IMN logo majestic logo threadwatch logo seochat tools logo