www.webdeveloper.com
Results 1 to 2 of 2

Thread: Enter has no effect on form text field

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    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="Υπολογισμός" onclick="calcResult();">
    </form>
    
    <table id="table_hba1c" style="display:none;">
    <tr>
    <td width="460"></td>
    <td width="200">Αποτέλεσμα</td>
    </tr>
    <tr>
    <td>Εκτιμώμενη μέση τιμή σακχάρου</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("Παρακαλώ καραχωρήστε την τιμή της HbA1c!");
    return false;
    }
    
    resultEl=(n*33.3-86).toFixed(1);
    m='mg/dl';
    d='Εκτιμώμενη μέση τιμή σακχάρου:&nbsp ';
    document.getElementById('resultl').innerHTML=resultEl + " " + m;
    document.getElementById('table_hba1c').style.display="table";
    }
    
    </script>

  2. #2
    Join Date
    Mar 2012
    Posts
    3
    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";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles