Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    82
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Pass a variable with html or javascript

    what i want is that i could send the value that is stored in the array

    For example i have array of
    result[0] = 1
    can i put in my form
    Code:
    <form action="2.html?right=result[0]&wrong=0" method="post">
    instead of 1?

    Code:
    <form action="2.html?right=1&wrong=0" method="post">
    html 1
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <script type="text/javascript">
    var result=new Array(); // regular array (add an optional integer
    result[0]=2;       // argument to control array's size)
    var a = parseInt(result[0]);
    result[1]="0";
    
    document.write(result[0]);
    document.write(a);
    
    
    </script>
    <table width="315" border="1">
      <tr>
        <td width="107"> -13-6=-23 </td>
        <td width="76"><form action="2.html?right=a&wrong=0" method="post"><INPUT TYPE="submit" VALUE="RIGHT"><input type="hidden" name="result[0]"/></form></td>
        <td width="110"><form action="2.html?right=0&wrong=1" method="post"><INPUT TYPE="submit" VALUE="WRONG"></form></td>
      </tr>
    </table>
    
    
    </body>
    </html>

    html 2
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <SCRIPT LANGUAGE="JavaScript">
    
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->
    
    <!-- Begin
    function getParams() {
    var idx = document.URL.indexOf('?');
    var params = new Array();
    if (idx != -1) {
    var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
    for (var i=0; i<pairs.length; i++) {
    nameVal = pairs[i].split('=');
    params[nameVal[0]] = nameVal[1];
       }
    }
    return params;
    }
    params = getParams();
    //  End -->
    </script>
    </head>
    
    <body>
    <table width="315" border="1">
      <tr>
        <td width="107"> -13-8=-21 </td>
        <td width="76">&nbsp;</td>
        <td width="110">&nbsp;</td>
      </tr>
    </table>
    <SCRIPT LANGUAGE="JavaScript">
    var result=new Array();
    <!-- Begin
    result[0] = 1;
    
    //result[0] = result[0] + parseInt(unescape(params["right"]));
    result[0] = unescape(params["right"]);
    result[1] = unescape(params["wrong"]);
    var name = unescape(params["name"]);
    
     // regular array (add an optional integer
    document.write(result[0] + result[1]);
    document.write(name);
    //  End -->
    </script>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Aug 2010
    Location
    India
    Posts
    42
    Thanks
    0
    Thanked 5 Times in 5 Posts
    You want to do it in client side script only?
    WHy not use server side script to handle requests?

  • #3
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    www.w3schools.com/php/default.asp

    PHP can handle this rather simply. Look over the tutorials in the link I gave.


  •  

    Posting Permissions

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