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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert dynamic data based on checkbox value

Status
Not open for further replies.

tamnet

IS-IT--Management
Jun 2, 2005
31
GB
I am using the follwoing code to try and insert data into 2 text fields if a checkbox is "checked" otherwise the fields are blank, but i do not seem to be able to find the correct syntax to make it work ?

Code:
<script language="JavaScript">
function showVal(){
  if (document.frmDesignDetails.chkDA.unchecked == True){
    document.frmDesignDetails.txtDABy.value = ""
    document.frmDesignDetails.txtDAD.value = ""
  }
  else{
    document.frmDesignDetails.txtDABy.value = "<%=ValImage%>"
    document.frmDesignDetails.txtDAD.value = "<%=strUKDate%>"
  }
}
</script>

Could anyone please help


Regards

Paul
 
Code:
<script language="JavaScript">
function showVal(){
  if ([b][COLOR=red]![/color][/b]document.frmDesignDetails.chkDA.[b][COLOR=red]checked[/color][/b]){
    document.frmDesignDetails.txtDABy.value = ""
    document.frmDesignDetails.txtDAD.value = ""
  }
  else{
    document.frmDesignDetails.txtDABy.value = "<%=ValImage%>"
    document.frmDesignDetails.txtDAD.value = "<%=strUKDate%>"
  }
}
</script>

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Additionally, as a side note, when checking to see if a value is equal to the boolean value "true" it is not necessary to put the "== true". If you decide to put it in anyway (if you think it's easier to read that way for instance), then make sure not to capitalize the T. Javascript is case sensitive, and the keyword is all lowercase letters: true

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
OK,
I have this working now with the following code

Code:
<script language="JavaScript">
function showVal(){
  if (document.frmDesignDetails.chkDA.checked){
    document.frmDesignDetails.txtDABy.value ="<%=ValImage%>"
    document.frmDesignDetails.txtDAD.value ="<%=strUKDate%>"
  }
  else{
    document.frmDesignDetails.txtDABy.value = ""
    document.frmDesignDetails.txtDAD.value = ""
  }
  
}
</script>

Now I need to replicate this for another checkbox and 2 other textfields however even though i have copied the code to create another function i cannot seem to get it to work. this is the other code
Code:
<script language="JavaScript">
function showValues(){
  if (document.frmDesignDetails.chkSTD.checked){
    document.frmDesignDetails.txtDRBy.value ="<%=ValImage%>"
    document.frmDesignDetails.txtDRD.value ="<%=strUKDate%>"
  }
  else{
    document.frmDesignDetails.txtDRBy.value = ""
    document.frmDesignDetails.txtDRD.value = ""
  }
}
</script>

and i have placed this for the checkbox
Code:
onChange="showValues()"

does anyone have any ideas why this will not work ??

Also would it be possible to carry out both sets of code from within one function ??


Regards

Paul
 
OK,
sorted the first bit out it was me being dumb.

Code:
onChange="showValues()"

only changes the values when you move to another field. Silly me.

changed it to
Code:
onClick="showValues()"
and it works fine.

however i would be interested to know if i could merge the two functions into one if someone has any suggestions




Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top