Solved

Coldfusion: Block certain fields based on input field

Posted on 2007-04-02
6
185 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 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
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.

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
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 insert an Iframe into WordPress. 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 : Open Page or Post…

691 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