Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code that only works with certain elements 1

Status
Not open for further replies.

optjco

IS-IT--Management
Apr 13, 2004
185
GB
Hi,
I have this code for disabling a submit button on an ASP page however although I only call it from one element if any of the other elements are empty then i cannot enable the button.

Could someone tell me if it is possible to only action the code from one textfield Please


Code:
<script Language = "javascript">
// Start Insert Complaint ID Function
function MoveCID()
{
var myVar = document.frmBoard.cmbComplaint.value
document.frmBoard.txtCID.value = myVar;
}// End Insert Complaint ID Function
</script>
<script Language = "javascript">
function maybeDisableButton()
{
 var dfe = document.frmBoard.elements;
 var disableButton = false;
 for(var i=0; i<dfe.length; i++)
 {
  if(dfe[i].value.length < 5)
  {
   disableButton = true;
   break;
  }//end if
  else
  {
   disableButton = false;
  }//end else
 }//end for

 document.frmBoard.Submit.disabled = disableButton;
}//end maybeDisableButton()
</script>

code to call function

Code:
onKeyUp = "maybeDisableButton()"

Regards

Olly
 
If you only need for it to check one textbox, then you could make it much simpler...

Code:
function maybeDisableButton(){
  if (document.frmBoard.txtCID.value == "someValue){
    document.frmBoard.Submit.disabled = false
  }
  else{
    document.frmBoard.Submit.disabled = true
  }
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
mwolf00,
sorry I mislead you there slightly I posted two bits of javascript code, the code I need to amend is as follows

Code:
<script Language = "javascript">
function maybeDisableButton()
{
 var dfe = document.frmBoard.elements;
 var disableButton = false;
 for(var i=0; i<dfe.length; i++)
 {
  if(dfe[i].value.length < 5)
  {
   disableButton = true;
   break;
  }//end if
  else
  {
   disableButton = false;
  }//end else
 }//end for

 document.frmBoard.Submit.disabled = disableButton;
}//end maybeDisableButton()
</script>

All i need is to make sure that a textarea("txtDetails" is populated with at least 5 characters.

I would appreciate it if you could point me in the right direction


Regards

Olly
 
This will do it, but it is more complex than it needs to be...

Code:
<script Language = "javascript">
function maybeDisableButton()
{
 var dfe = document.frmBoard.elements;
 var disableButton = false;
 for(var i=0; i<dfe.length; i++)
 {
  [b][COLOR=blue]if (dfe[i].name == "txtDetails"){[/color][/b]
   if(dfe[i].value.length < 5)
   {
    disableButton = true;
    break;
   }//end if
   else
   {
    disableButton = false;
   }//end else
  [b][COLOR=blue]}[/color][/b]
  
 }//end for

 document.frmBoard.Submit.disabled = disableButton;
}//end maybeDisableButton()
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
mwolf00,
works great thanks a lot, just one more question ? on my page I have 15 fields would it be possible to use the code to make sure that say 3 fields were populated or would I need the javascript code in there 3 times. Sorry for all the questions but I am trying to learn as I go along

Regards

Olly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top