change value upon select

Posted by Link on Stack Overflow See other posts from Stack Overflow or by Link
Published on 2012-09-11T21:33:50Z Indexed on 2012/09/11 21:38 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

what i'm aiming is to show the other div when it selects one of the two options Full time and Part Time

and if possible compute a different value for each When the user selects Part time the value of PrcA will change to PrcB

this is the code i used

<!====================================================================================>


<script language="javascript">
<!--//

function dm(amount) 
{
  string = "" + amount;
  dec = string.length - string.indexOf('.');
  if (string.indexOf('.') == -1)
  return string + '.00';
  if (dec == 1)
  return string + '00';
  if (dec == 2)
  return string + '0';
  if (dec > 3)
  return string.substring(0,string.length-dec+3);
  return string;
}



function calculate()
{

  QtyA = 0;  
  TotA = 0;  

  PrcA = 1280; 
  PrcB = 640; 


  if (document.form1.qtyA.value > "")
     { QtyA = document.form1.qtyA.value };
  document.form1.qtyA.value = eval(QtyA);  



  TotA = QtyA * PrcA;
  document.form1.totalA.value = dm(eval(TotA));


  Totamt = 

     eval(TotA) ;

  document.form1.GrandTotal.value = dm(eval(Totamt));


} 


//-->
</script>


<!====================================================================================>
<p>
<label for="acct" style="margin-right:90px;"><strong>Account Type<strong><font color=red size=3> * </font></strong></label>
<select name="acct" style="background-color:white;" class="validate[custom[serv]] select-input" id="acct" value="">


                <option value="Full Time">Full-Time</option>
                <option value="Part Time">Part-Time</option>
                <option selected="selected" value=""></option>

</select></p>

<!====================================================================================>
<script>
$(document).ready(function() {
    $("input[name$='acct']").select(function() {
        var test = $(this).val();

        $("div.desc").hide();
        $("#acct" + test).show();
    });
});
</script>


<!====================================================================================>
<p>
<table><tr><td>
<lable style="margin-right:91px;"># of Agent(s)<font color=red size=3> * </font></lable>
</td><td>
<input style="width:25px; margin-left:5px;" type="text" class="validate[custom[agnt]] text-input" name="qtyA" id="qtyA" onchange="calculate()" />
</td><td>
<div id="acctFull Time" class="desc">
 x 1280 = 
</div>
<div id="acctPart Time" class="desc" style="display:none">
 x 640 = 
</div>
</td><td>
$<input style="width:80px; margin-left:5px;" type="text" readonly="readonly"  name="totalA" id="totalA" onchange="calculate()" />
</p>
</td></tr></table>

is there any way for me to achieve this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html