Home All Groups Group Topic Archive Search About

Javascript two fields merged to one hidden field

Author
12 Dec 2005 5:57 AM
Microsoft_Public
All I'm getting is <null>......

I have a legacy input form that I must maintain for a few more months until
the balance of the site can be converted to .Net.

I need the one database field to contain either 0, 1, 2.

The form has 2 pairs of radio button fields.

If the answer to the first Q is Yes value = 1
then add the result of the 2 pairs of input options
is assigned to the "Hidden" input field.

If the first ans is No value = 0
and that value is assigned to the "Hidden" input field.

..... snipit, code omitted....

  && validReplace(document.forms[0].APPLICANT_EXIST_INSUR,
document.forms[0].APPLICANT_REPLACE_INPUT);
        }
..... code omitted....
function validReplace(formField1, formField2)
{
  var existIns = formField1.value;
  var replace = formField2.value;
  if(existIns = "0") {
   APPLICANT_REPLACE.value == existIns;
  } else {
   APPLICANT_REPLACE.value == (existIns ++ replace);
   }
  return APPLICANT_REPLACE;
}

...... code omited....

        <td>Do you have existing insurance policies?</td>
        <td align=right valign=top>
            <table border=0 cellspacing="0" cellpadding="0">
            <tr>
            <td valign=middle><input type="radio"
name="APPLICANT_EXIST_INSUR" value="1"></td><td>Yes &nbsp;</td>
            <td><input type="radio" name="APPLICANT_EXIST_INSUR"
value="0"></td><td>No &nbsp;</td>
            </tr>
            </table>
        </td>
</tr>
        <tr><td colspan=2 bgcolor=#000000><img src="images/clear.gif"
height=1 border=0></td></tr>
        <tr>
        <td>Are you planning on replacing any insurance policies?</td>
        <td align=right valign=top>
            <table border=0 cellspacing="0" cellpadding="0">
            <tr>
            <td valign=middle><input type="radio"
name="APPLICANT_REPLACE_INPUT" value="1"></td><td>Yes &nbsp;</td>
            <td><input type="radio" name="APPLICANT_REPLACE_INPUT"
value="0"></td><td>No &nbsp;</td>
            </tr>
            </table>
  <input type="hidden" name="APPLICANT_REPLACE" value="">
        </td>

Author
12 Dec 2005 1:07 PM
Karl Seguin
I don't know if it's just the tool u used to post but...

ur using assignment operators (=) when you should be using equality
operators (==) and I have no idea what ++ is supposed to mean.

Is validReplace supposed to return true/false, or is it supposed to return
the value to put in the hidden form field, or both?

function validReplace(formField1, formField2)
{
   var applicationReplace = document.forms[0].APPLICANT_REPLACE;
   var existIns = formField1.value;
   var replace = formField2.value;

   if(existIns == "0") {
     applicationReplace.value = existIns;
     return false;  //maybe you want to return true here, don't really
follow ur return logic...
                    //maybe you simply want to return applicationReplace
   }
   //no need for an else, if the above IF was true, you returned in there
and would never get here
   applicationReplace.value = existIns + replace;
   return true;  //again figure out what you want to return
}

Karl

Show quoteHide quote
"Microsoft_Public" <NojpgmtSpam@sbcglobal.net> wrote in message
news:eI3oxDu$FHA.3096@TK2MSFTNGP14.phx.gbl...
>
> All I'm getting is <null>......
>
> I have a legacy input form that I must maintain for a few more months
> until the balance of the site can be converted to .Net.
>
> I need the one database field to contain either 0, 1, 2.
>
> The form has 2 pairs of radio button fields.
>
> If the answer to the first Q is Yes value = 1
> then add the result of the 2 pairs of input options
> is assigned to the "Hidden" input field.
>
> If the first ans is No value = 0
> and that value is assigned to the "Hidden" input field.
>
> .... snipit, code omitted....
>
>  && validReplace(document.forms[0].APPLICANT_EXIST_INSUR,
> document.forms[0].APPLICANT_REPLACE_INPUT);
>        }
> .... code omitted....
> function validReplace(formField1, formField2)
> {
>  var existIns = formField1.value;
>  var replace = formField2.value;
>  if(existIns = "0") {
>   APPLICANT_REPLACE.value == existIns;
>  } else {
>   APPLICANT_REPLACE.value == (existIns ++ replace);
>   }
>  return APPLICANT_REPLACE;
> }
>
> ..... code omited....
>
>        <td>Do you have existing insurance policies?</td>
>        <td align=right valign=top>
>            <table border=0 cellspacing="0" cellpadding="0">
>            <tr>
>            <td valign=middle><input type="radio"
> name="APPLICANT_EXIST_INSUR" value="1"></td><td>Yes &nbsp;</td>
>            <td><input type="radio" name="APPLICANT_EXIST_INSUR"
> value="0"></td><td>No &nbsp;</td>
>            </tr>
>            </table>
>        </td>
> </tr>
>        <tr><td colspan=2 bgcolor=#000000><img src="images/clear.gif"
> height=1 border=0></td></tr>
>        <tr>
>        <td>Are you planning on replacing any insurance policies?</td>
>        <td align=right valign=top>
>            <table border=0 cellspacing="0" cellpadding="0">
>            <tr>
>            <td valign=middle><input type="radio"
> name="APPLICANT_REPLACE_INPUT" value="1"></td><td>Yes &nbsp;</td>
>            <td><input type="radio" name="APPLICANT_REPLACE_INPUT"
> value="0"></td><td>No &nbsp;</td>
>            </tr>
>            </table>
>  <input type="hidden" name="APPLICANT_REPLACE" value="">
>        </td>
>
>
>
Are all your drivers up to date? click for free checkup

Author
14 Dec 2005 8:27 AM
JDP@Work
I'm sorry I wasn't perfectly clear, my ++ was my "attempt" to add the values as
integers.

If the value of the first question is 1 (yes) then add that to the value of the
2nd question,
either 1 + 0 = 1, or 1 + 1 = 2, however it occurs to me that I should set the
2nd value if it's empty (null).

If the value of the 2nd question is 1, I don't want to add that to the first
question as,
0 + 1 = 1 that would be bad, logicially you can't replace what you don't have,
see below.....

In my db, 0 = no existing ins, and not replacing, and a 1 = existing insurance,
2 means existing insurance and replacing.

TIA

JeffP.....

Show quoteHide quote
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:e4rfL0x$FHA.2040@TK2MSFTNGP14.phx.gbl...
> I don't know if it's just the tool u used to post but...
>
> ur using assignment operators (=) when you should be using equality
> operators (==) and I have no idea what ++ is supposed to mean.
>
> Is validReplace supposed to return true/false, or is it supposed to return
> the value to put in the hidden form field, or both?
>
> function validReplace(formField1, formField2)
> {
>    var applicationReplace = document.forms[0].APPLICANT_REPLACE;
>    var existIns = formField1.value;
>    var replace = formField2.value;
>
>    if(existIns == "0") {
>      applicationReplace.value = existIns;
>      return false;  //maybe you want to return true here, don't really
> follow ur return logic...
>                     //maybe you simply want to return applicationReplace
>    }
>    //no need for an else, if the above IF was true, you returned in there
> and would never get here
>    applicationReplace.value = existIns + replace;
>    return true;  //again figure out what you want to return
>  }
>
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
> http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
>
>
>
> "Microsoft_Public" <NojpgmtSpam@sbcglobal.net> wrote in message
> news:eI3oxDu$FHA.3096@TK2MSFTNGP14.phx.gbl...
> >
> > All I'm getting is <null>......
> >
> > I have a legacy input form that I must maintain for a few more months
> > until the balance of the site can be converted to .Net.
> >
> > I need the one database field to contain either 0, 1, 2.
> >
> > The form has 2 pairs of radio button fields.
> >
> > If the answer to the first Q is Yes value = 1
> > then add the result of the 2 pairs of input options
> > is assigned to the "Hidden" input field.
> >
> > If the first ans is No value = 0
> > and that value is assigned to the "Hidden" input field.
> >
> > .... snipit, code omitted....
> >
> >  && validReplace(document.forms[0].APPLICANT_EXIST_INSUR,
> > document.forms[0].APPLICANT_REPLACE_INPUT);
> >        }
> > .... code omitted....
> > function validReplace(formField1, formField2)
> > {
> >  var existIns = formField1.value;
> >  var replace = formField2.value;
> >  if(existIns = "0") {
> >   APPLICANT_REPLACE.value == existIns;
> >  } else {
> >   APPLICANT_REPLACE.value == (existIns ++ replace);
> >   }
> >  return APPLICANT_REPLACE;
> > }
> >
> > ..... code omited....
> >
> >        <td>Do you have existing insurance policies?</td>
> >        <td align=right valign=top>
> >            <table border=0 cellspacing="0" cellpadding="0">
> >            <tr>
> >            <td valign=middle><input type="radio"
> > name="APPLICANT_EXIST_INSUR" value="1"></td><td>Yes &nbsp;</td>
> >            <td><input type="radio" name="APPLICANT_EXIST_INSUR"
> > value="0"></td><td>No &nbsp;</td>
> >            </tr>
> >            </table>
> >        </td>
> > </tr>
> >        <tr><td colspan=2 bgcolor=#000000><img src="images/clear.gif"
> > height=1 border=0></td></tr>
> >        <tr>
> >        <td>Are you planning on replacing any insurance policies?</td>
> >        <td align=right valign=top>
> >            <table border=0 cellspacing="0" cellpadding="0">
> >            <tr>
> >            <td valign=middle><input type="radio"
> > name="APPLICANT_REPLACE_INPUT" value="1"></td><td>Yes &nbsp;</td>
> >            <td><input type="radio" name="APPLICANT_REPLACE_INPUT"
> > value="0"></td><td>No &nbsp;</td>
> >            </tr>
> >            </table>
> >  <input type="hidden" name="APPLICANT_REPLACE" value="">
> >        </td>
> >
> >
> >
>
>
Author
14 Dec 2005 2:35 PM
Karl Seguin
0 = no existing insurance, not replacing
1 = existing insurance
2 = existing insurance and replacing

and there's no case for no insurance and replacing I guess...that simply
isn't valid?
Seems to me the simplest way to do this and to simply code the logic as we
describe. Why add things together when our rules are so simple?

var existingInsurnace = parseInt(formField1.value);
var replacing = parseInt(formField2.value);

if (existingInsurance == 1 && replacing == 1)
{
    value = 2;  //existing insurance and replacing
}
else if (existingInsurance == 1)
{
   value = 1;  existing insurance
}
else
{
   value = 0; neither
}

it might not be magical, but it's awfully straightforward and self-evident.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


Show quoteHide quote
"JDP@Work" <JPGMTNoSpam@sbcglobal.net> wrote in message
news:ec5bqbIAGHA.216@TK2MSFTNGP15.phx.gbl...
> I'm sorry I wasn't perfectly clear, my ++ was my "attempt" to add the
> values as
> integers.
>
> If the value of the first question is 1 (yes) then add that to the value
> of the
> 2nd question,
> either 1 + 0 = 1, or 1 + 1 = 2, however it occurs to me that I should set
> the
> 2nd value if it's empty (null).
>
> If the value of the 2nd question is 1, I don't want to add that to the
> first
> question as,
> 0 + 1 = 1 that would be bad, logicially you can't replace what you don't
> have,
> see below.....
>
> In my db, 0 = no existing ins, and not replacing, and a 1 = existing
> insurance,
> 2 means existing insurance and replacing.
>
> TIA
>
> JeffP.....
>
> "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in
> message news:e4rfL0x$FHA.2040@TK2MSFTNGP14.phx.gbl...
>> I don't know if it's just the tool u used to post but...
>>
>> ur using assignment operators (=) when you should be using equality
>> operators (==) and I have no idea what ++ is supposed to mean.
>>
>> Is validReplace supposed to return true/false, or is it supposed to
>> return
>> the value to put in the hidden form field, or both?
>>
>> function validReplace(formField1, formField2)
>> {
>>    var applicationReplace = document.forms[0].APPLICANT_REPLACE;
>>    var existIns = formField1.value;
>>    var replace = formField2.value;
>>
>>    if(existIns == "0") {
>>      applicationReplace.value = existIns;
>>      return false;  //maybe you want to return true here, don't really
>> follow ur return logic...
>>                     //maybe you simply want to return applicationReplace
>>    }
>>    //no need for an else, if the above IF was true, you returned in there
>> and would never get here
>>    applicationReplace.value = existIns + replace;
>>    return true;  //again figure out what you want to return
>>  }
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/
>> http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
>>
>>
>>
>> "Microsoft_Public" <NojpgmtSpam@sbcglobal.net> wrote in message
>> news:eI3oxDu$FHA.3096@TK2MSFTNGP14.phx.gbl...
>> >
>> > All I'm getting is <null>......
>> >
>> > I have a legacy input form that I must maintain for a few more months
>> > until the balance of the site can be converted to .Net.
>> >
>> > I need the one database field to contain either 0, 1, 2.
>> >
>> > The form has 2 pairs of radio button fields.
>> >
>> > If the answer to the first Q is Yes value = 1
>> > then add the result of the 2 pairs of input options
>> > is assigned to the "Hidden" input field.
>> >
>> > If the first ans is No value = 0
>> > and that value is assigned to the "Hidden" input field.
>> >
>> > .... snipit, code omitted....
>> >
>> >  && validReplace(document.forms[0].APPLICANT_EXIST_INSUR,
>> > document.forms[0].APPLICANT_REPLACE_INPUT);
>> >        }
>> > .... code omitted....
>> > function validReplace(formField1, formField2)
>> > {
>> >  var existIns = formField1.value;
>> >  var replace = formField2.value;
>> >  if(existIns = "0") {
>> >   APPLICANT_REPLACE.value == existIns;
>> >  } else {
>> >   APPLICANT_REPLACE.value == (existIns ++ replace);
>> >   }
>> >  return APPLICANT_REPLACE;
>> > }
>> >
>> > ..... code omited....
>> >
>> >        <td>Do you have existing insurance policies?</td>
>> >        <td align=right valign=top>
>> >            <table border=0 cellspacing="0" cellpadding="0">
>> >            <tr>
>> >            <td valign=middle><input type="radio"
>> > name="APPLICANT_EXIST_INSUR" value="1"></td><td>Yes &nbsp;</td>
>> >            <td><input type="radio" name="APPLICANT_EXIST_INSUR"
>> > value="0"></td><td>No &nbsp;</td>
>> >            </tr>
>> >            </table>
>> >        </td>
>> > </tr>
>> >        <tr><td colspan=2 bgcolor=#000000><img src="images/clear.gif"
>> > height=1 border=0></td></tr>
>> >        <tr>
>> >        <td>Are you planning on replacing any insurance policies?</td>
>> >        <td align=right valign=top>
>> >            <table border=0 cellspacing="0" cellpadding="0">
>> >            <tr>
>> >            <td valign=middle><input type="radio"
>> > name="APPLICANT_REPLACE_INPUT" value="1"></td><td>Yes &nbsp;</td>
>> >            <td><input type="radio" name="APPLICANT_REPLACE_INPUT"
>> > value="0"></td><td>No &nbsp;</td>
>> >            </tr>
>> >            </table>
>> >  <input type="hidden" name="APPLICANT_REPLACE" value="">
>> >        </td>
>> >
>> >
>> >
>>
>>
>
>

Bookmark and Share