<script type="text/javascript">
function validate(){
var x = 2;
document.write(x + '\n'); //output: 2
add(x) //add()をCall
console.log(x); //output: 2
}
function add(x){
var y = 1;
var z = x+y;
document.write(z); //output: 3
}
validate()
</script>
=============================================
もうひとつ、すごく苦労した受け渡し
=============================================
function startOver() {
document.loan_form.loan_amt.value="0";
document.loan_form.months.value="0";
document.loan_form.rate.value="0";
document.loan_form.extra.value="";
document.getElementById("loan_info").innerHTML = "";
document.getElementById("table").innerHTML = "";
}
function validate(){
var loan_amt = document.loan_form.loan_amt.value;
var months = document.loan_form.months.value;
var rate = document.loan_form.rate.value;
var extra = document.loan_form.extra.value;
if(loan_amt <= 0 || isNaN(Number(loan_amt))){
alert("please enter a valid loan amount.");
document.loan_form.loan_amt.value = "0";
}
else if (months <=0 || parseInt(months) != months){
alert("please enter a valid number of months.");
document.loan_form.months.value = "0";
}
else if (rate <= 0 || isNaN(Number(rate))){
alert("please enter a valid interest rate.");
document.loan_form.loan_amt.value = "0";
}
else if (extra < 0 || isNaN(Number(extra))){
alert("please enter a valid extra payment.");
document.loan_form.loan_amt.value = "0";
}
else{
alert("validation complete");
alert(parseFloat(loan_amt) +'/n'+ parseInt(months))
calculate(parseFloat(loan_amt),parseInt(months),parseFloat(rate),parseFloat(extra));
// calculate function()に渡すvaluewを()内で指定
//str型から其々の数字に
}
}
function calculate(loan_amt,months,rate,extra){
console.log(loan_amt + 1000 + 'hello'+ months + 'add' + rate+'extra'+extra);
}
0 件のコメント:
コメントを投稿