?
Solved

Coldfusion: Block certain fields based on input field

Posted on 2007-04-02
6
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
stu215 earned 600 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 5

Assisted Solution

by:mihaimm
mihaimm earned 400 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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 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…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

752 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