Click here to Skip to main content
15,890,438 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Getting started with Javascript Pin
Gerd Wagner24-Feb-15 9:41
professionalGerd Wagner24-Feb-15 9:41 
AnswerRe: Getting started with Javascript Pin
Member 1148300326-Feb-15 7:22
Member 1148300326-Feb-15 7:22 
AnswerRe: Getting started with Javascript Pin
Praveen Raghuvanshi5-Apr-15 6:39
professionalPraveen Raghuvanshi5-Apr-15 6:39 
QuestionWhat is the function of Extracting String Characters in JavaScript Pin
Member 1144603412-Feb-15 6:01
Member 1144603412-Feb-15 6:01 
AnswerRe: What is the function of Extracting String Characters in JavaScript Pin
Richard Deeming12-Feb-15 6:23
mveRichard Deeming12-Feb-15 6:23 
GeneralRe: What is the function of Extracting String Characters in JavaScript Pin
Santosh K. Tripathi31-Mar-15 2:04
professionalSantosh K. Tripathi31-Mar-15 2:04 
QuestionI want to write it in aspx or ascx file Pin
indian14310-Feb-15 12:50
indian14310-Feb-15 12:50 
Generalusing ajax Pin
Member 113542638-Feb-15 18:58
Member 113542638-Feb-15 18:58 
I'm trying to to send form data to PHP via ajax but printout shows zero values. My JS editor indicates that one of the scripts below (commented) is invalid. I don't see it. help?

JavaScript
<!DOCTYPE html><html>
    <!--To POST data like an HTML form, add an HTTP header with 

setRequestHeader
    (). Specify the data you want to send in the send() method:-->
    <head>
    <meta charset=utf-8>
    <title>calculator insert form</title>
    <style type="text/css">
    input{
    text-align:center;
    }
    </style>
    </head>
    <body><center>
<input type="text" size="45" align="middle" value="enter purpose 

in box below" ><br>
<input type="text" align="middle" name="purpose" size="45" > 
    <FORM name="Keypad" 

action="http://localhost/home/calcinsert.php" method="post">
    <TABLE>
    
    <TABLE border=2 width=50 height=60 cellpadding=1 

cellspacing=5>
    <TR>
    <TD colspan=3 align=middle>
    <input name="ReadOut" type="Text" size=24 value="0"     

width=100%></TD>
    <TD></TD>
  <TD><input name="btnClear" type="Button" value="   C    " 

onclick="Clear()"></TD>
  <TD><input name="btnClearEntry" type="Button" value="    CE    " 

onclick="ClearEntry()"></TD>
    </TR><TR>
  <TD><input name="btnSeven" type="Button" value="    7    " 

onclick="NumPressed(7)"></TD>
  <TD><input name="btnEight" type="Button" value="    8    " 

onclick="NumPressed(8)"></TD>
  <TD><input name="btnNine" type="Button" value="    9    " 

onclick="NumPressed(9)"></TD>
      <TD></TD>
  <TD><input name="btnNeg" type="Button" value="   +/-   " 

onclick="Neg()"></TD>
    <TD><input name="btnPercent" type="Button" value="    %    " 

onclick="Percent()"></TD>
      </TR><TR>
  <TD><input name="btnFour" type="Button" value="    4    " 

onclick="NumPressed(4)"></TD>
   <TD><input name="btnFive" type="Button" value="    5    " 

onclick="NumPressed(5)"></TD>
   <TD><input name="btnSix" type="Button" value="    6    " 

onclick="NumPressed(6)"></TD>
      <TD></TD>
   <TD align=middle><input name="btnPlus" type="Button" value="    

+    " onclick="Operation('+')"></TD>
   <TD align=middle><input name="btnMinus" type="Button" value="   

 -    " onclick="Operation('-')"></TD>
      </TR><TR>
   <TD><input name="btnOne" type="Button" value="    1    " 

onclick="NumPressed(1)"></TD>
   <TD><input name="btnTwo" type="Button" value="    2    " 

onclick="NumPressed(2)"></TD>
    <TD><input name="btnThree" type="Button" value="    3    " 

onclick="NumPressed(3)"></TD>
      <TD></TD>
    <TD align=middle><input name="btnMultiply" type="Button" 

value="    *    " onclick="Operation('*')"></TD>
    <TD align=middle><input name="btnDivide" type="Button" value=" 

   /    " onclick="Operation('/')"></TD>
      </TR><TR>
    <TD><input name="btnZero" type="Button" value="    0    " 

onclick="NumPressed(0)"></TD>
    <TD><input name="btnDecimal" type="Button" value="    .    " 

onclick="Decimal()"></TD>
      <TD colspan=3></TD>
 
<td><input type="button" name="btnEquals" class="red" value="    = 

     " onClick="Operation('='); this.form.submit();
event.returnValue = false;"></td>

    </TR></TABLE></TABLE></FORM>

<a href="http://localhost/home/calcprint.php">Print</a>
    </CENTER>
    <font face="Verdana, Arial, Helvetica" size=2>

    <script>
    var FKeyPad = document.Keypad;
    var Accumulate = 0;
    var FlagNewNum = false;
    var PendingOp = "";
    function NumPressed (Num)
 {
    if (FlagNewNum)
    {FKeyPad.ReadOut.value = Num;FlagNewNum = false;}
   else {if (FKeyPad.ReadOut.value == "0") FKeyPad.ReadOut.value = 

Num;
    else FKeyPad.ReadOut.value += Num;}
 }
    function Operation (Op)
 {
    var Readout = FKeyPad.ReadOut.value;
    if (FlagNewNum && PendingOp != "=");
    else
 {
    FlagNewNum = true;
    if ( '+' == PendingOp )
    Accumulate += parseFloat(Readout);
    else if ( '-' == PendingOp )
    Accumulate -= parseFloat(Readout);
    else if ( '/' == PendingOp )
    Accumulate /= parseFloat(Readout);
    else if ( '*' == PendingOp )
    Accumulate *= parseFloat(Readout);
    else
    Accumulate = parseFloat(Readout);
    FKeyPad.ReadOut.value = Accumulate;
    PendingOp = Op;
 }
  }
    function Decimal ()
 {
    var curReadOut = FKeyPad.ReadOut.value;
    if (FlagNewNum)
    {curReadOut = "0.";FlagNewNum = false;}
    else
    {if (curReadOut.indexOf(".") == -1) curReadOut += ".";}
    FKeyPad.ReadOut.value = curReadOut;
 }
    function ClearEntry ()
    {FKeyPad.ReadOut.value = "0";FlagNewNum = true;}
    function Clear ()
    {Accumulate = 0;PendingOp = "";ClearEntry();}
    function Neg ()
    {FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * 

-1;}
    function Percent ()
    {FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 

100) * parseFloat(Accumulate);}
    </SCRIPT>

// ************error indicated in below script********

    <script>
    var js_var = "<br />whatever";
    document.getElementById("link").onclick = OnCalc ();
 { 
               // ajax start
    var xhr;
    if (window.XMLHttpRequest) xhr = new XMLHttpRequest();
    else xhr = new ActiveXObject("Microsoft.XMLHTTP"); // for IE
var url = 'http://localhost/home/calcinsert.php?js_var=' + js_var;
    xhr.open('GET', url, false);
    xhr.onreadystatechange = function ()
 { 
    if (xhr.readyState===4 && xhr.status===200)
 { 
    var div = document.getElementById("update");
    div.innerHTML=xhr.responseText;
 }
  };
    xhr.send();
    // ajax stop
    return false;
 }
    </script>
    </body></html>
--------------------
--------------
PHP
<?php
$servername = "localhost";$username = "root";$password = "cookie";
$dbname = "homedb";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn)
   { die("Connection failed: " . mysqli_connect_error()); }
$sql = "INSERT INTO calculator (purpose, value1, op, value2, total)
VALUES ('purpose', 'value1', 'op', 'value2', 'total')";
if (mysqli_query($conn, $sql))
   {
 echo "<center>";   
 echo "data entered<br><br>"; 
  } 
else
   { echo "Error: " . $sql . "<br>" . mysqli_error($conn); }
mysqli_close($conn);

header( "refresh:3;url='xxxxxxx'");
echo "<center>";
echo 'I\m old and slow</br>
in a rush, click 
<a href="http://localhost/home/calcform.html">here</a>.'
     ?>

-------------------------------------

SuggestionRe: using ajax Pin
ZurdoDev9-Feb-15 8:47
professionalZurdoDev9-Feb-15 8:47 
GeneralRe: using ajax Pin
Member 113542639-Feb-15 13:30
Member 113542639-Feb-15 13:30 
QuestionWhat is an AXD file Pin
indian1433-Feb-15 14:58
indian1433-Feb-15 14:58 
AnswerRe: What is an AXD file Pin
Richard Deeming4-Feb-15 2:17
mveRichard Deeming4-Feb-15 2:17 
GeneralRe: What is an AXD file Pin
indian1434-Feb-15 6:20
indian1434-Feb-15 6:20 
GeneralRe: What is an AXD file Pin
Richard Deeming4-Feb-15 6:39
mveRichard Deeming4-Feb-15 6:39 
GeneralRe: What is an AXD file Pin
indian1434-Feb-15 6:52
indian1434-Feb-15 6:52 
QuestionHow to make ondrop event being invoked by mouseover? Pin
Member 113783023-Feb-15 6:12
Member 113783023-Feb-15 6:12 
QuestionCalling an ASMX Web Service through JQuery .Ajax Pin
dbrenth2-Feb-15 10:44
dbrenth2-Feb-15 10:44 
QuestionRe: Calling an ASMX Web Service through JQuery .Ajax Pin
ZurdoDev2-Feb-15 11:00
professionalZurdoDev2-Feb-15 11:00 
AnswerRe: Calling an ASMX Web Service through JQuery .Ajax Pin
dbrenth3-Feb-15 2:28
dbrenth3-Feb-15 2:28 
QuestionRe: Calling an ASMX Web Service through JQuery .Ajax Pin
ZurdoDev3-Feb-15 2:30
professionalZurdoDev3-Feb-15 2:30 
AnswerRe: Calling an ASMX Web Service through JQuery .Ajax Pin
dbrenth3-Feb-15 2:57
dbrenth3-Feb-15 2:57 
GeneralRe: Calling an ASMX Web Service through JQuery .Ajax Pin
ZurdoDev3-Feb-15 3:02
professionalZurdoDev3-Feb-15 3:02 
GeneralRe: Calling an ASMX Web Service through JQuery .Ajax Pin
dbrenth3-Feb-15 5:14
dbrenth3-Feb-15 5:14 
GeneralRe: Calling an ASMX Web Service through JQuery .Ajax Pin
ZurdoDev3-Feb-15 5:34
professionalZurdoDev3-Feb-15 5:34 
AnswerRe: Calling an ASMX Web Service through JQuery .Ajax Pin
Richard Deeming4-Feb-15 2:12
mveRichard Deeming4-Feb-15 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.