Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Dynamically change style properties in Coldfusion

Is there a way to dynamically change a style property in CF?

For example the following code sample has a form with a select input that toggles a second select input to display or hide via Javascript.

Once the form is submitted, I'd like the 2nd select to display based on what it's state was before the form was submitted.

Something like <select name="mySelect2" style="display:<cfif Form.mySelect2.style="display:inline;">inline<cfelse>none</cfif>;">
Please let me know if I'm way off base and should extend the Javascript somehow to get the desired result (not a clue how to do that!).

Code Sample:
<html>
<head>
<title>Code Demo</title>
<script language="JavaScript" type="text/javascript">
      function toggle(i){
            if(i.form.mySelect1.value == 2){
                  i.form.mySelect2.style.display = "inline"
            }
            else {
                  i.form.mySelect2.style.display="none"
            }
      }
</script>

</head>

<body>

<div style="margin-top:25%;margin-left:25%;">
<form name="frm" action="Demo.cfm" method="post">
            <select name="mySelect1"onchange="toggle(this);">
                  <option value="1" selected="selected">One</option>
                  <option value="2">Two</option>
                  <option value="3">Three</option>
                        </select>
            
            <select name="mySelect2" style="display:none;">
                  <option value="1" selected="selected">One</option>
                  <option value="2">Two</option>
                  <option value="3">Three</option>
                        </select>
            <br /><br />
            <input name="" type="submit" />
</form>
</div>

</body>
</html>
0
rmosher315
Asked:
rmosher315
  • 3
1 Solution
 
tim_csCommented:
You should be able to do something like that only instead of checking the style of mySelect2 with the cfif you would want to check the value of myselect1 being equal to 2.  

Something like this.  

<select name="mySelect2" style="display:<cfif Form.mySelect1 = 2>inline<cfelse>none</cfif>;">
0
 
tim_csCommented:
doh, make sure you use "EQ" and not "="

<cfif Form.mySelect1 EQ 2>
0
 
rmosher315Author Commented:
Y'know... some things are just TOO obvious.  Thanks Tim, it works like a charm!  The points are yours.
0
 
tim_csCommented:
thanks, glad I could help.  
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now