Jump to content

please somebody help me


narjis

Recommended Posts

I want to pass an json array by using javascript and then pass to a php script. Hewre's my script


<!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>Random Box changing colors</title>
<script type="text/javascript" language="javascript">
function ToggleBackgrnd(){
/* this function checks the length of each character in input block_*/
var jsonObj = [];
var x;
/*for (x=0;x<8;x++){
	num[x] = array.push(document.getElementById("block_"+ x));

 for (var i = 0; i < 5; i++) {
	 x =document.getElementById("block_"+ i);
        jsonObj.push({i: x});
 }

//console.log(jsonObj);
$.post("randomEg.php",jsonObj,function(data){
alert(data);});
}
</script>
</head>

<body>
<form method="post" action="">
  <p>Enter Password  </p>
  <table width="200" border="0" align="center">
    <tr>
      <td width="12"><label for="block_1"></label>
        <input name="block_1" type="password" id="block_1" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_2" type="password" id="block_2" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_3" type="password" id="block_3" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_4" type="password" id="block_4" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_5" type="password" id="block_5" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_6" type="password" id="block_6" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_7" type="password" id="block_7" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_8" type="password" id="block_8" size="1" maxlength="1" /></td>
    </tr>
  </table>
  <p>
   
    <input type="submit" name="submit" value="Post" onclick="ToggleBackgrnd();" />
  </p>
</form>
</body>
</html>[code]

Link to comment
Share on other sites

I've uncommented it now here my 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>Random Box changing colors</title>
</head>

<body>
<form method="post" action="">
  <p>Enter Password  </p>
  <table width="200" border="0" align="center">
    <tr>
      <td width="12"><label for="block_1"></label>
        <input name="block_1" type="password" id="block_1" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_2" type="password" id="block_2" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_3" type="password" id="block_3" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_4" type="password" id="block_4" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_5" type="password" id="block_5" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_6" type="password" id="block_6" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_7" type="password" id="block_7" size="1" maxlength="1" /></td>
      <td width="12"><input name="block_8" type="password" id="block_8" size="1" maxlength="1" /></td>
    </tr>
  </table>
  <p>
   
    <input type="submit" name="submit" value="Post" onclick="ToggleBackgrnd();" />
  </p>
</form>
<script type="text/javascript" language="javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript" language="javascript">
function ToggleBackgrnd(){
/* this function checks the length of each character in input block_*/
var jsonObj = [];
var x;
var y;
 for (var i = 1; i < 6; i++) {
	 y="block_"+ i;
	 x =document.getElementById(y).value;
        jsonObj.push({i: x});
	//document.write(x);
 }
// console.log(jsonObj);
	$.post("randomArreg.php",jsonObj,function(data){
alert("success");
});



}
</script>

</body>
</html>

Now the console is printing the result but some how it is not showing print_r($_POST['jsonObj'])

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.