Reputation: 41
I have a function code like below
function setShort() {
var f = document.editFrm;
var x = 10;
//var project_company = f.project_parent..value;
//project_name from database, 76 = project_parent's id
if (f.project_name.value.length < 11) {
x = f.project_name.value.length;
}
if (f.project_short_name.value.length >= 0 && f.project_parent.value == 76) {
var w = 0;
var y = "UKSP-LC-12-"+(w+1);
f.project_short_name.value = y;
return w = w+1;
//f.project_short_name.value = project_company;
}
this function is for selectlist, which mean if the user click the project_parent which id = 76
, it will show to another textfield which is project_short_name
.
So how can i code it let w
cannot be repeated to 0 but can continue +1
after the first 0
saved, is it possible that use loop?
Or can i count the rows of the project parent so that i no need to use loop and just w(total rows of project_parent from sql)+1
, im a newbie of loop and js, hope you guys have some ideas
Upvotes: 0
Views: 69
Reputation: 71918
Declare w
outside the function:
var w = 0;
function setShort() {
// ...
// remove line below:
// var w = 0;
// ....
}
Upvotes: 1