This topic is locked
[SOLVED]

 Javascript on load

10/13/2017 8:25:00 PM
PHPRunner General questions
mtpocket author

Greetings
I have a table called stock.

Int - ID

Item - varchar

Stock_on_hand - decimal

Required - decimal
When a user requires stock, he/she can choose how many they require whilst seeing Stock_on_hand.

The user should not be able request more than what is currently in stock "Stock_on_hand".

I'm looking at "Calculate total on the fly" but cannot seem to apply it, when I insert a digit it just disappears again.
Below is my Javascript on load

var ctrlRequired = Runner.getControl(pageid, 'Required');

var ctrlStock_on_hand = Runner.getControl(pageid, 'Stock_on_hand');

function func() {

ctrlRequired.setValue(Number(ctrlRequired.getValue()) < Number(ctrlStock_on_hand.getValue()));

};

ctrlRequired.on('keyup', func);
Perhaps someone can guide me into the right direction.
Thanks

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=25078&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />

Y
YCH 10/14/2017



Greetings
I have a table called stock.

Int - ID

Item - varchar

Stock_on_hand - decimal

Required - decimal
When a user requires stock, he/she can choose how many they require whilst seeing Stock_on_hand.

The user should not be able request more than what is currently in stock "Stock_on_hand".

I'm looking at "Calculate total on the fly" but cannot seem to apply it, when I insert a digit it just disappears again.
Below is my Javascript on load

var ctrlRequired = Runner.getControl(pageid, 'Required');

var ctrlStock_on_hand = Runner.getControl(pageid, 'Stock_on_hand');

function func() {

ctrlRequired.setValue(Number(ctrlRequired.getValue()) < Number(ctrlStock_on_hand.getValue()));

};

ctrlRequired.on('keyup', func);
Perhaps someone can guide me into the right direction.
Thanks

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=83466&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />


You may try inserting a if-clause to handle input error
function func() {

if (Number(ctrlRequired.getValue()) < Number(ctrlStock_on_hand.getValue()))

{

ctrlRequired.setValue(Number(ctrlRequired.getValue()));

}

else

{

//some error message;

}

ctrlRequired.on('keyup', func);