Reputation: 17
I have created an inline javascript to test a button but the button isn't working when clicked.
I thought maybe the js code is wrong but I tested the button with a simple alert and it still not working can you help pls? Here is the HTML / and a sample js script.
function calcEquation() {
alert("hello");
<form id="form-ckd" method="post">
<div id="ckd-calc">
<div class="card">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">CKD calculator</h6>
</div>
<div class="card-body">
<p>Sex of patient:</p>
<div>
<label class="radio-inline">
<input type="radio" name="sex-ckd" value="m"> Male
</label>
<label class="radio-inline">
<input type="radio" name="sex-ckd" value="f"> Female
</label>
<br /><br />
<p>Ethnicity:</p>
<label class="radio-inline">
<input type="radio" name="race-ckd" value="b"> Black
</label>
<label class="radio-inline">
<input type="radio" name="race-ckd" value="o"> Other
</label>
<br /><br />
<p>Age of patient (years):</p>
<input type="number" min="1" max="120" name="age-ckd" />
<br /><br />
<p>Serum creatinine (micromol/L):</p>
<input type="number" min="1" max="120" name="serum-ckd" />
<br />
</div>
<br />
<hr />
<div id="ckd-result">
<h5 id="outs-ckd"></h5>
<p>Glomerular Filtration Rate by the MDRD Equation: <a href="https://www.mdcalc.com/mdrd-gfr-equation#evidence" style="color:white;"><u> mdcalc website</u></a></p>
</div>
<button type="button" class="btn btn-primary" onclick="calcEquation();">Calculate</button>
<button type="button" class="btn btn-danger" onclick="popup.hideEquationFormPopup();">Close</button>
<button type="reset" class="btn btn-primary" onclick="resetCKD();">Reset</button>
</div>
</div>
</div>
</form>
Upvotes: 0
Views: 115
Reputation: 21
That's because you've missed a closed curly bracket on the function calcEquation :) .
<script type=text/javascript>
function calcEquation(){
alert("hello");}
</script>
<form id="form-ckd" method="post">
<div id="ckd-calc">
<div class="card">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">CKD calculator</h6>
</div>
<div class="card-body">
<p>Sex of patient:</p>
<div>
<label class="radio-inline">
<input type="radio" name="sex-ckd" value="m"> Male
</label>
<label class="radio-inline">
<input type="radio" name="sex-ckd" value="f"> Female
</label>
<br /><br />
<p>Ethnicity:</p>
<label class="radio-inline">
<input type="radio" name="race-ckd" value="b"> Black
</label>
<label class="radio-inline">
<input type="radio" name="race-ckd" value="o"> Other
</label>
<br /><br />
<p>Age of patient (years):</p>
<input type="number" min="1" max="120" name="age-ckd" />
<br /><br />
<p>Serum creatinine (micromol/L):</p>
<input type="number" min="1" max="120" name="serum-ckd" />
<br />
</div>
<br />
<hr />
<div id="ckd-result">
<h5 id="outs-ckd" ></h5>
<p >Glomerular Filtration Rate by the MDRD Equation: <a href="https://www.mdcalc.com/mdrd-gfr-equation#evidence" style="color:white;"><u> mdcalc website</u></a></p>
</div>
<button type="button" class="btn btn-primary" onclick="calcEquation();">Calculate</button>
<button type="button" class="btn btn-danger" onclick="popup.hideEquationFormPopup();">Close</button>
<button type="reset" class="btn btn-primary" onclick="resetCKD();">Reset</button>
</div>
</div>
</div>
</form>
Upvotes: 2
Reputation: 499
<script type=text/javascript>
function calcEquation(){
alert("hello");
</script>
I think you forgot to close the function with }
in the end.
Upvotes: 4