Jump to content
Sign in to follow this  
vdb@telenet.be

Howto Add +1 To A Number-Field With Update Datapage?

Recommended Posts

I found already this, but it concatenate instead of addition...

Can anybody make this script work?

 

<SCRIPT LANGUAGE="JavaScript">

 

function add()

{

 

var position1 =document.getElementById("EditRecordR397_Gegrilde_eend_sappig").value;

 

var position2 = 1

 

 

var allpositions = position1 + position2;

 

document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value =allpositions;

 

}

 

document.getElementById("caspioform").onsubmit=add;

</SCRIPT>>

Share this post


Link to post
Share on other sites

I can add numbers now, but i can not do the 'if then' check..

When Virtual1 is "Y" then add +1 to Fieldxx

 

Thank you if you could help me out..

Bart

 

 

 

<SCRIPT LANGUAGE="JavaScript">

 

function add()

{

 

var totalVal = parseInt((document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value)) + (+1)

 

document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value =totalVal;

 

}

 

 if (document.getElementById("@cbParamVirtual1").value == "Y") {

    document.getElementById("caspioform").onsubmit=add;

 }

 

</SCRIPT>>

Share this post


Link to post
Share on other sites

Check the line var totalVal = parseInt((document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value)) + (+1)

as it is missing a ";".  Also  if (document.getElementById("@cbParamVirtual1").value == "Y"), remove the "@".

 

Have you tried the following:

 

var is_checked = document.getElementByID("cbParamVirtual1").checked;

if(is_checked){

   document.getElementById("caspioform").onsubmit=add;

}

Share this post


Link to post
Share on other sites

hi GoCubbies,

thank you for the advice.

 

I tested all, but still not add +1 when the checkbox is checked.

The code for adding +1 to another field is working, but it is like the if-then code is not detecting anything?

I am searching this for 2 days already.

Maybe you can see other faults?

 

thanx,

Bart

Belgium

 

the updated code:

 

<SCRIPT LANGUAGE="JavaScript">

 

function add()

{

 

var totalVal = parseInt((document.getElementById

 

("EditRecordR393_Kip_met_Marrokaanse_kruiden").value;)) + (+1)

 

 

document.getElementById

 

("EditRecordR393_Kip_met_Marrokaanse_kruiden").value; =totalVal;

}

 

function is_checked_and_change()

{

   var is_checked = document.getElementById("cbParamVirtual1").checked;

 

   if (is_checked)

      {

         document.getElementById("caspioform").onsubmit=add;

      }

}

 

</SCRIPT>>

Share this post


Link to post
Share on other sites

Hello Mel,

 

If I understand correctly, you can use the following code:

<SCRIPT LANGUAGE="JavaScript">
function add()
{
var is_checked = document.getElementById("cbParamVirtual1").checked;
if (is_checked)
 {
   var totalVal = parseInt(document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value);
   totalVal = totalVal + 1;
   document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value=totalVal;
   }
}
document.getElementById("caspioform").onsubmit=add; 
</SCRIPT>

And it requires set the field R393_Kip_met_Marrokaanse_kruiden as Hidden, select Data Source Fields in the On load assign drop down box, and selet your field in the next drop down box.

 
I hope, it helps.

Share this post


Link to post
Share on other sites

I tested this with checkbox and radiobuttons, did not work.

 

Only List and dropdown give the info...

 

Finaly i worked with this to add up 1 to the existing amount:

 

<script language="JavaScript">
function concatenate()
{
var position1 = parseInt(document.getElementById("cbParamVirtual1").value);
var position2 = parseInt(document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value);
var allpositions = position1 + position2;
document.getElementById("EditRecordR393_Kip_met_Marrokaanse_kruiden").value=allpositions;
}
document.getElementById("caspioform").onsubmit=concatenate;
</SCRIPT>

 

 

many thanx!

Mel

Share this post


Link to post
Share on other sites

Mel,

 

In terms of the code Jan provided, my understanding is that the virtual field as a checkbox did not function.  Are there other virtual fields present on the page, or is this checkbox the only one. The reason I ask is that the naming of the form element of virtual fields may be the issue.  As a reference, take a look at http://forums.caspio.com/index.php/topic/4377-js-guide-caspio-form-elements/.

 

I was able to test out Jan's code both with a virtual checkbox field and a YES/NO datatype field from table and it worked in a test page that I created.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...