form values with maths
Posted: Mon Aug 09, 2010 4:42 am
hi all, i have been working on a script for a friend, ran into a bit of a dead end though... the form needs income details, weekly or monthly inputs. we have a field for weekly and a field for monthly, and when somebody puts a weekly, or monthly amount in, the other amount fills it's self in automatically. The only thing is if i enter 10 in weekly i get 43.333333333333336 as monthly. I need this to be rounded or cut to 2 decimal placesand then inserted. Here is the code i have to do it so far
you may notice i have only done half of the script, this is as if it all needs changing it may be easier not doing the whole script now.
Also how would i make sure the entered value is a number and not letters before it is submitted?
Thanks
Code: Select all
<input name="incomemainwk" length="40" id="incomemainwk" value="Main" onFocus="if(this.value=='Main') this.value='';" onblur="if(this.value==''){ this.value='Main'; incomemainmo.value='Main'} else{ incomemainmo.value=(this.value*52)/12};"><br>
<input name="incomepartnerwk" length="40" id="incomepartnerwk" value="Partner" onFocus="if(this.value=='Partner') this.value='';" onblur="if(this.value==''){ this.value='Partner'; incomepartnermo.value='Partner'} else{ incomepartnermo.value=(this.value*52)/12};"><br>
<input name="incomebenefitswk" length="40" id="incomebenefitswk" value="Benefits" onFocus="if(this.value=='Benefits') this.value='';" onblur="if(this.value==''){ this.value='Benefits'; incomebenefitsmo.value='Benefits'} else{ incomebenefitsmo.value=(this.value*52)/12};"><br>
<input name="incomeotherwk" length="40" id="incomeotherwk" value="Other" onFocus="if(this.value=='Other') this.value='';" onblur="if(this.value==''){ this.value='Other'; incomeothermo.value='Other'} else{ incomeothermo.value=(this.value*52)/12};">
<br><br>
<input name="incomemainmo" length="40" id="incomemainmo" value="Main" onFocus="if(this.value=='Main') this.value='';" onblur="if(this.value=='') this.value='Main';"><br>
<input name="incomepartnermo" length="40" id="incomepartnermo" value="Partner" onFocus="if(this.value=='Partner') this.value='';" onblur="if(this.value=='') this.value='Partner';"><br>
<input name="incomebenefitsmo" length="40" id="incomebenefitsmo" value="Benefits" onFocus="if(this.value=='Benefits') this.value='';" onblur="if(this.value=='') this.value='Benefits';"><br>
<input name="incomeothermo" length="40" id="incomeothermo" value="Other" onFocus="if(this.value=='Other') this.value='';" onblur="if(this.value=='') this.value='Other';">Also how would i make sure the entered value is a number and not letters before it is submitted?
Thanks