Random number in hidden field
Random number in hidden field
Hello Allan,
I have a new question
I need a random number in a hidden field in editor.
What I have is this:
var editor = new $.fn.dataTable.Editor( {
"ajax": "adm_artikel_processing.php",
"table": "#pm_artikel",
"fields": [
{
"label": "Name",
"name": "tm_pen_artikel.Name"
},
{
"label": "code",
"name": "tm_pen_artikel.code",
"def": function (val){
var min = 1111111111;
var max = 9999999999;
var zufall = Math.floor(Math.random() * (max - min + 1)) + min;
return val = zufall;
},
"type": "hidden"
},
{
"label": "Beschreibung",
"name": "tm_pen_artikel.Beschreibung"
},
{
"label": "Preis",
"name": "tm_pen_artikel.Preis",
attr: {
type: 'number',
lang: 'de'
}
}
],
But with this solution, the number is every time the same.
I need a new number after every new entry and after edit an entry.
How can I do this? Is this possible?
Rappi
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I tried your random code and it generates a different number each time i open the editor. I checked it but not hiding the field. Have you tried that to verify?
EDIT: I'll let those more familiar with Javascript comment but I don't think you want
function(val)
but instead wantfunction()
and change your return statement toreturn zufall;
.Kevin
@Kevin, I agree. That function made no sense to me, but I'm no expert.
Hi Kevin,
thanks.
That's it!
Rappi