Seppo Kuusela Seppo Kuusela - 2 months ago 5
HTML Question

Getting name="" from div with $_POST

i am trying to get

$_POST["number"]
from
<div name="number" class="total"></div>
class total is attached with
`

var count = 0;
$('button').click(function(){
count++;
count > 3 || $('.total').append($(this).val());
});`


When i try to get the
$_POST["number"]
Notice: Undefined index: number in C:\xampp\htdocs\index.php on line 67

EDIT:

If that won't work how i can get that JQuery value inside to that value=""

Thanks to @Barry Thomas for helping me. Here is the fix:

<form method="POST" action="">
Name <input name="name" type="text"></input> <br /><br />
Number <div id="codebar">
<input type="hidden" name="number" id="form_number" value="">
<div id="div_number" class="total"></div>
</div>
<br>

<input name="submit" type="submit"></input>
</form>

var count = 0;
$('button').click(function(){
count++;
count > 3 || $('.total').text($(this).val());
$('#form_number').val($('#div_number').text());

});

Answer

Your code:

<form method="POST" action="">
    Name <input name="name" type="text"></input> <br /><br />
    Number <div id="codebar">
    <input type="hidden" id="form_number" value="">
<div name="number" id="div_number" class="total"></div>
</div>
<br>

<input name="submit" type="submit"></input>
</form>

Move the name="number" on to the input, like so.

<form method="POST" action="">
    Name <input name="name" type="text"></input> <br /><br />
    Number <div id="codebar">
    <input type="hidden" name="number" id="form_number" value="">
    <div id="div_number" class="total"></div>
</div>
<br>

<input name="submit" type="submit"></input>
</form>

The form input was missing name="number" so when it posted there was no $_POST['number']

var count = 0;
$('button').click(function(){
    count++;
  count > 3 || $('.total').text($(this).val());
  **$('#form_number').val($('#div_number').text());**

});
Comments