0

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

When I hit submit on my on page the info does go into the database but I keep on getting undefined for some and im not getting the bounce data from sample in the javascript.


Notice: Undefined index: sample in

<div id="have"><  id="<?php echo 'sample' ?>" onChange="calcnum()"width="500" 
     height="500" style="border:1pt solid black"></div>
      <input type="hidden" name="number" id="number" />
<form action="<?php echo $editFormAction; ?>" method="POST" name="form">
<input name="save" type="hidden"  value="<? echo $_POST['sample']?>" />
<input name="submit" type="submit" onChange="calcnum()" value="submit" />
<input type="hidden" name="MM_insert" value="savelayout" />
    </form>

And java -

    <script type="text/javascript">

  function calc()
   {

     if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
   }
    else
  {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    val1 = document.getElementById("sample").value;


    xmlhttp.onreadystatechange=function()
               {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
{

  document.getElementById("sample").innerHTML=xmlhttp.responseText;
  document.getElementById("sample").value = xmlhttp.responseText;

}}
   }
 </script>

Any pointers would greatly be appreciated thanks :)

Community
  • 1
  • 1
  • 1
    What's going on here: "
    < id="" onChange="calcnum()"width="500" height="500" style="border:1pt solid black">
    "
    – Boundless Jan 14 '13 at 02:07
  • 1
    Yeah I was just about to ask the same thing. What exactly are you trying to accomplish with your code? – kittycat Jan 14 '13 at 02:08
  • also this code is calling `calcnum()` and not `calc()` – Class Jan 14 '13 at 02:12
  • how it works is someone marks or circles a image and then it saves it in the database.. but it saves it as text... I know how to bring up the text.. I am just having a hard time bouncing the text.. which it shows fine on sample.. As for the id="" I tried to use id="sample" and that part didn't work either.. Thanks for the calnum to i missed that –  Jan 14 '13 at 03:06
  • Really? That doesn't answer my question at all and doesn't even come close to what I am asking about.. why would you close it? How do you reopen this? Why is it with stackoverflow the last 4 questions I have asked have gotten minus's and they where never really answered.. ???? –  Jan 14 '13 at 12:35

1 Answers1

1

To fix the undefined error change this:

<? echo $_POST['sample']?>

to this:

<? if (isset($_POST['sample'])) {echo $_POST['sample'];} ?>
kittycat
  • 14,983
  • 9
  • 55
  • 80