/    Sign up×
Community /Pin to ProfileBookmark

Enter has no effect on form text field

I made a small script for a formula calculation and what I have not managed to do yet, is make the Enter act as pressing the button.
Any help please?
Here is the form:

[CODE]<form id=hba1c action=”” method=”post” name=”HbA1c_form”>
Hba1c% <input type=”text” id=”userValue” size=”15″><input type=”button” value=”&#933;&#960;&#959;&#955;&#959;&#947;&#953;&#963;&#956;&#972;&#962;” onclick=”calcResult();”>
</form>

<table id=”table_hba1c” style=”display:none;”>
<tr>
<td width=”460″></td>
<td width=”200″>&#913;&#960;&#959;&#964;&#941;&#955;&#949;&#963;&#956;&#945;</td>
</tr>
<tr>
<td>&#917;&#954;&#964;&#953;&#956;&#974;&#956;&#949;&#957;&#951; &#956;&#941;&#963;&#951; &#964;&#953;&#956;&#942; &#963;&#945;&#954;&#967;&#940;&#961;&#959;&#965;</td>
<td id=”resultl”></td>
</tr>
</table>

<script type=”text/javascript”>
function calcResult() {
n=document.getElementById(‘userValue’).value
n=parseFloat(n);
var userValue=document.forms[“hba1c”][“userValue”].value;

if (userValue==null || userValue==””)
{
alert(“&#928;&#945;&#961;&#945;&#954;&#945;&#955;&#974; &#954;&#945;&#961;&#945;&#967;&#969;&#961;&#942;&#963;&#964;&#949; &#964;&#951;&#957; &#964;&#953;&#956;&#942; &#964;&#951;&#962; HbA1c!”);
return false;
}

resultEl=(n*33.3-86).toFixed(1);
m=’mg/dl’;
d=’&#917;&#954;&#964;&#953;&#956;&#974;&#956;&#949;&#957;&#951; &#956;&#941;&#963;&#951; &#964;&#953;&#956;&#942; &#963;&#945;&#954;&#967;&#940;&#961;&#959;&#965;:&nbsp ‘;
document.getElementById(‘resultl’).innerHTML=resultEl + ” ” + m;
document.getElementById(‘table_hba1c’).style.display=”table”;
}

</script>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@hariskarauthorMar 27.2012 — Actually on hitting Enter I don't want the form to be submited.

I would like these to start:
[CODE]document.getElementById('resultl').innerHTML=resultEl + " " + m;
document.getElementById('table_hba1c').style.display="table";[/CODE]
×

Success!

Help @hariskar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...