Solved

Coldfusion: Block certain fields based on input field

Posted on 2007-04-02
6
180 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now