Solved

Coldfusion: Block certain fields based on input field

Posted on 2007-04-02
6
183 Views
Last Modified: 2013-12-16
I have a form with 7 fields (fields 1 thru 7). If field1=A, fields 2, 3 and 4 should be blocked and fields 5, 6 and 7 can be entered. If field1=B, the other side around, fields 2, 3 and 4 can be entered and fields 5,6 and 7 blocked.

How can I accomplish this in coldfusion?

Thanks.

Errol
0
Comment
Question by:Errol Farro
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
stu215 earned 150 total points
ID: 18839299
Coldfusion is a server side technology therefore it cant make changes dynamically on the client side.

However you can use javascript ( theres also cfscript which is similar to javascript ) ::

<script>
function chkMyField(){
      if (document.form1.radio1[0].checked==true){
            document.form1.txt2.disabled=true;
            document.form1.txt3disabled=true;
            document.form1.txt4disabled=true;
            document.form1.txt5.disabled=false;
            document.form1.txt6.disabled=false;
            document.form1.txt7.disabled=false;
            document.form1.txt5.focus();
      } else if (document.form1.radio1[1].checked==true){
            document.form1.txt2.disabled=false;
            document.form1.txt3.disabled=false;
            document.form1.txt4.disabled=false;
            document.form1.txt5.disabled=true;
            document.form1.txt6.disabled=true;
            document.form1.txt7.disabled=true;
            document.form1.txt2.focus();
      } else {
            document.form1.txt2.disabled=true;
            document.form1.txt3.disabled=true;
            document.form1.txt4.disabled=true;
            document.form1.txt5.disabled=true;
            document.form1.txt6.disabled=true;
            document.form1.txt7.disabled=true;
      }
}
</script>

<body onLoad="chkMyField();">

<form name="form1">
<input type="radio" name="radio1" value="A" onChange="chkMyField();"/>
<input type="radio" name="radio1" value="B" onChange="chkMyField();"/><br />


<input name="txt2" size="10" value="" /><br />
<input name="txt3" size="10" value="" /><br />
<input name="txt4" size="10" value="" /><br />
<input name="txt5" size="10" value="" /><br />
<input name="txt6" size="10" value="" /><br />
<input name="txt7" size="10" value="" /><br />
</form>

</body>
0
 
LVL 5

Expert Comment

by:mihaimm
ID: 18839921
Also remember validate on server side as java script can be easily disabled and you can't do anything about it. In case something is invalid, return to the page with an error message.
0
 

Author Comment

by:Errol Farro
ID: 18843999
I tried your code and it worked fine with the radio button but actually I have a drop down list with 5 values.
If the field is value1 then it should do part 1, else it should do part 2. I don't know scripting very well. How do I do I change the if line ( if (document.form1.radio1[0].checked==true)) to handle a drop down field?

Thanks. Errol
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 5

Assisted Solution

by:mihaimm
mihaimm earned 100 total points
ID: 18844596
say you have
<select name="select1">......</select>

Then you change the code posted by stu215 in
if (document.form1.select1.selectedIndex == 0){
...
} else if (document.form1.select1.selectedIndex == 1){
...
} else {
....
}
0
 
LVL 10

Expert Comment

by:stu215
ID: 18844682
Hey,

Doh, had a busy morning @ work but yep, what mihaimm put should work for a drop down.

~Stu :-)
0
 

Author Comment

by:Errol Farro
ID: 18844958
Thanks a lot for your help Guys. It's working. Regards. Errol
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question