Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: validate with hide and show field

$
0
0

use this

 

function show(a,b) {

document.getElementById(a).style.display = "block";

document.getElementById(b).style.display = "none";

}

function hide(a,b) {

document.getElementById(a).style.display = "none";

document.getElementById(b).style.display = "none";

}

 

 

function control()

{

          if(document.form.approve[0].checked == false && document.form.approve[1].checked == false)

          {

                    alert('choose selection');

                    return false;

          }

 

          if(document.form.approve[0].checked == true && document.form.txt1.value == '')

          {

                    alert('write something to txt1');

                    return false;

          }

 

          if(document.form.approve[1].checked == true && document.form.txt2.value == '')

          {

                    alert('write something to txt2');

                    return false;

          }

}

 

 

<cfform action="test.cfm" method="post" name="form" id="form" onsubmit="return control();">

      <cfinput type="radio" name="approve" value="1" onclick="show('d0','d1'); ">One<br>

       <div id="d0">

         <cfinput type="text" name="txt1">name<br>

        </div>

 

     <cfinput type="radio" name="approve" value="1" onclick="show('d1','d0'); ">Two<br>

      <div id="d1">

         <cfinput type="text" name="txt2">city<br>

        </div>

    <cfinput type="submit" name="submit" value="Save">

  </cfform>


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>