www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript conversion problem

  1. #1
    Join Date
    Oct 2010
    Posts
    4

    Javascript conversion problem

    Hi all,

    First of all thanks for everyone who responds to me. I appreciate it.

    Here is my problem.


    I have a HTML form containing two text box controls in it and a submit button. When a user enters information in those two textboxes and click on submit, the information is sent to a function in Javascript. In the javascript, the information from those textboxes is stored in a javascript variable.

    The problem is as follows:

    When I am inputting string text in the html text boxes and in the javascript when I am trying to print those values, it is giving me out an error saying NaN. However when i input integer values in the text boxes it is printing those numbers. Is there a conversion that I have to do for the string to be printed. I am new to Javascript and need your help. This is a basic code of Javascript. Below is the code that I have. Thanks in advance for your help.


    <html>
    <script type = "text/javascript">

    function square(form)
    {


    var test = form.value1.value;
    window.alert(+test);

    var point = document.test.value1.value;
    pointcon = point.toString();

    window.alert("nice");
    window.alert(+pointcon);

    var point2 = eval(document.test.value2.value);

    var point3 = point + point2;
    alert(point3);

    }

    </script>



    <head>
    <body>
    <form name = "test">
    First name: <input type="text" name = "value1" value1 = ""/><br />
    Last name: <input type="text" name = "value2" value2 = ""/>
    <input type = "button" value = "Submit" onClick="square(this.form)"/>
    </form>
    </body>

    </html>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    First name: <input type="text" name = "value1" value1 = ""/><br />
    Last name: <input type="text" name = "value2" value2 = ""/>
    What's that for. You have some custom attributes named as the name values. Confusing

  3. #3
    Join Date
    Oct 2010
    Posts
    4
    I thought that was the syntax for it. Isn't that the syntax?

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by gsashwin View Post
    I thought that was the syntax for it. Isn't that the syntax?
    Code:
    First name: <input type="text" name = "value1" value1 = ""/><br />
    Last name: <input type="text" name = "value2" value2 = ""/>
    Syntax for what? value1 and value2 are not native HTML attributes. And try to make your variable more distinct. You have too many things named the same.

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