Click here to Skip to main content
15,896,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I must apologize, am new here, sorry if my format is wrong.
What I would like is to have my convertFnction(con1) put the converted data back into
the input line where it will be submitted by user.

The idea is to have the user type in 5 numbers and the convertFunction() return value will be put in the 'input line' as the converted value. Then 'submit' it.
A side note: It seems that passing in the number to the function is sometimes problematic,
not sure why.

HTML
<pre lang="text"><pre lang="HTML"><pre lang="CSS"><pre lang="Javascript">
<pre lang="Javascript">
HTML
<pre lang="CSS"><pre lang="Javascript"><pre lang="xml"><form method="get" action="forms_wifi.html">
    <td>Convert_test:</td>
    <td><input type="text" size=31 name="Con1" value="Con1"  onclick="convertFunction('Con1')"> </td>
    <td><input type="submit"  value="Submit" > </td> <!-- '54321' works  -->
    </form>


<script type="text/javascript">

JavaScript
    function convertFunction(convalue)
    {
        var con1 = convalue;
        var m = "54321";
        var n = con1.localeCompare(m);

        if(n == 0)          /* var n = str1.localeCompare(str2); 95673 */
        {
            value = "good";   // put value in input line.
            alert("95673");   // debug alert
            return "95673";
        }
        else
        {
            value = "nogood";  // value of input line.
            alert("nogood");
            return "nogood";
        }
    }
</script>
Posted

You purpose and the purpose of the onclick handler (convertFunction) remain unclear to me; all looks weird. But one problem is apparent: you complain about passing data to a function, but instead pass some string constant, "Con1". What would you expect then?

Whatever you want to do, you need to pass some variable related to the text input control. Most general way is to pass its reference, "this". Please see how this sample works:
HTML
<html>

   <head>
      <script>
         function onTextClick(data) {
            alert(data.value);
         }			
      </script>
   </head>

<body>
   <input type="text" value="some text value" onclick="onTextClick(this)">
</body>

</html>


In this sample alert call will show the text entered in the input element using this handler. In your "real" handler, you can do with this data whatever you want. Even if this is something weird. :-)

—SA
 
Share this answer
 
Comments
JimOr 10-Aug-14 7:04am    
Thank you Sergey,
I will try your proposed solution. Then adapt it to what I am trying to do.
Will comment more after tests later today.
Thanks Kindly,
Jim
Sergey Alexandrovich Kryukov 10-Aug-14 13:27pm    
You are welcome. Will you accept the answer formally (green "Accept" button)? I think the technique is clear to you.
—SA
Sergey,
I clicked the green button to accept the solution but nothing happened.....
Except that the button now says 'Reject'.
And I do not want to Reject. Did I do something wrong?

I will have more questions soon.

Kindly,
Jim
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900