Page 1 of 1

Change date

Posted: Tue Mar 13, 2012 2:31 am
by CoCiX
Hi,
i have two fields,loan_type and member_type, that i take the values from a database and another field with date.
When i choose the values from that field which are specific i want to change the date
for example in sql i would write it something like that
SELECT CURRENT_DATE + INTERVAL
CASE WHEN membership_type = 'staff'
AND Loan_type = 'short' THEN 10
WHEN membership_type = 'staff'
AND Loan_type = 'long' THEN 20
WHEN membership_type = 'student'
AND Loan_type = 'short' THEN 30
WHEN membership_type = 'student'
AND Loan_type = 'long' THEN 40 END DAY

how can i do that in nubuilder? with php or javascript?

Re: Change date

Posted: Tue Mar 13, 2012 11:18 pm
by admin
CoCiX,

Do you know php and javascript?

Steven

Re: Change date

Posted: Wed Mar 14, 2012 1:45 am
by CoCiX
Hey,
yes but i am not expert i tried this one but it is not working
var first = 6;
var second = 12;
var third = 18;
var forth = 24;

var fi = (document.getElementById("due_date");


fi = new Date();
lo = document.getElementById("loan_type").value;
mem = document.getElementById("mem_type").value;
if(lo = 1 && mem = 1)
{
fi.setDate(fi.getDate() + first);
alert(fi);
}
else if(lo = 2 && mem = 1)
{
fi.setDate(fi.getDate() + second);
alert(fi);
}
else if((lo = 1 && mem = 2)
{
fi.setDate(fi.getDate() + third);
alert(fi);
}
else
fi.setDate(fi.getDate() + forth);
alert(fi);

Re: Change date

Posted: Wed Mar 14, 2012 4:18 pm
by admin
CoCiX,

You have at least 2 places where you have an opening bracket without a closing bracket and one place where you set fi to an HTML object and then to a date.

I suggest you write 1 or 2 lines at a time and get that working, or put alert()s or nuDebug()s http://wiki.nubuilder.com/tiki-index.ph ... g_pString_ through your code to see where things break.

This forum is really about nuBuilder and how PHP and JavaScript work with it.

For general help with PHP and JavaScript you really need to look elsewhere.

Steven