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

Checkbox to control 2 hidden form values 1

Status
Not open for further replies.
Aug 1, 2003
85
US
Hi All,
I've come across the need to have a single checkbox supply values to 2 hidden form fields to submit to the database.
Code:
<script language="JavaScript">
		   var temp
		   var vari1active
		   var variFin_Date		   
function finished()
{
    if (form1.temp.checked == true)
    {
        vari1active  = 1;
      variFin_Date = now();
  }
}
</SCRIPT> 

<td><input name="temp" type="checkbox" id="temp" onclick="finished()" /></td>

<input type="hidden" name="Fin_Date" value="variFin_Date">
<input type="hidden" name="Active" value="vari1active">\
[code]

I'm sure I've butchered this code and I'm mixing up javascript and vbscript. Help Plz!!
 
try:

Code:
<script language="JavaScript">
          
function finished() {
    var f = document.forms['yourFormName'];
    var d = f.elements['variFin_Date'];
    var a = f.elements['vari1active'];

    if ( f.elements['temp'].checked ) {
        a.value = 1;
        f.value = new date();
    }
}
</SCRIPT>

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
thanks for such a quick response!! I pasted the code and got page error = elements is null or not an object
 
I changed f.value to d.value and Ive got this now

<script language="JavaScript">
function finished() {
var f = document.forms['form1'];
var d = f.elements['variFin_Date'];
var a = f.elements['vari1active'];

if ( f.elements['temp'].checked ) {
a.value = 1;
d.value = new date();
}
}
</SCRIPT>

with the error 'undefined' is null or not an object
 
This should get you started.

<html>
<head><title>Test</title>
<script language="JavaScript">

function finished()
{
var tmpDate = new Date();


if (document.test.temp.checked == true)
{
document.test.Active.value = 1;
document.test.Fin_Date.value = tmpDate;

alert(document.test.Active.value);
alert(document.test.Fin_Date.value);

}

}
</SCRIPT>
</head>

<form name="test" id="test" option="">
<input name="temp" type="checkbox" id="temp" onclick="return finished();" />

<input type="hidden" name="Fin_Date" value="">
<input type="hidden" name="Active" value="">
</form>
</html>
 
That did the trick!! Thank You! 1 quick question though. Is there a way to format new Date() to just output 8/18/2005 5:34:23 PM as in general date?
 
I've finished tweaking 4345487's code, here's what I have now

function finished()
{
if (document.form1.temp.checked == true)
{
document.form1.Active.value = 1;
document.form1.Fin_Date.value = "<%= now() %>";
}
}
</SCRIPT>

<td>
<input name="temp" type="checkbox" id="temp" onclick="finished()">
</td>

<input type="hidden" name="Fin_Date" value="">
<input type="hidden" name="Active" value="">

Thanks again 4345487!
 
function finished()
{

var tmpDate = new Date();
var YY = tmpDate.getFullYear();
var MM = tmpDate.getMonth();
var DD = tmpDate.getDate();

var tmpDate_1 = MM + "/" + DD + "/" + YY;

if (document.form1.temp.checked == true)
{
document.form1.Active.value = 1;
document.form1.Fin_Date.value = tmpDate_1;
}
}
</SCRIPT>

<td>
<input name="temp" type="checkbox" id="temp" onclick="finished()">
</td>

<input type="hidden" name="Fin_Date" value="">
<input type="hidden" name="Active" value="">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top