Jump to content

Using a Button to fill a field


Recommended Posts

Hello. 

I have created a simple button using HTML and CSS. I was wondering if I can incorporate this into my DataPage. My Idea is that if the button, named Bulk,  is clicked, it will automatically fill the "Quantities" field.

I am not too sure what to fill the Quantities field with yet, as the datatype set for it is a Number. Most orders have a quantity number ordered, but if it is a ton, I would like it so the user can just click "Bulk" so that the receiving department is aware.

Link to comment
Share on other sites

Hello @kpcollier,

If you just want to add a value in your "Quantities field" when "Bulk button" is clicked, you can add this code in the footer of your DataPage:

Quote

<script>
document.getElementsByName('Bulk')[0].onclick = function(){ 

document.getElementById('InsertRecordQuantites').value = "The value you want to automatically fill the field";
};
</script>

Note: Make sure that you unchecked the "Enabled HTML Editor" in your footer.

I hope this helps :)

Link to comment
Share on other sites

Hey @WatashiwaJin, I appreciate the reply. I have put this in my footer section. The quantities field is named "Qty_Ordered", would I replace InsertRecordQuantities with InsertRecordQty_Ordered? I have tried it like this an was unable to get a response in my app. 

Here is how I built the button. Maybe its because I used a hyperlink instead of input=button?

https://codepen.io/kpcollier/pen/PydqKq

Link to comment
Share on other sites

Actually, I still can't get it to actually fill the quantity field. When I click it, it submits the form. But, when I go to the table, the Quantity field is still empty. I did rename my field "Qty_Ordered" to just "Quantity" and did the same for the JS.

In my debugger I am getting an Uncaught TypeError "Cannot set property 'onclick' of undefined".

I thought onclick was an inherited function from JS, so I am confused as to why this is happening.

Edited by kpcollier
Uncaught TypeError
Link to comment
Share on other sites

Hi @WatashiwaJin

I've been messing with this to try to get it to work. 

document.getElementsByName('Bulk').onclick = function(){myFunction()};

function myFunction() {document.getElementById('InsertQuantity').value = "100";
};

This removed the onclick error. But it still doesn't fill Quantity to 100.

*Edit

I might've done too much. Putting [0] after 'Bulk' creates the onclick error. Taking it out prevents the error but still does not work. I tried to log a message through the console in the function and didn't get any response... so my function does not work lol.

*Edit #2

https://howto.caspio.com/datapages/ajax-loading/

Found this in the online help article listed above.

  • onload(), onsubmit() and other loading events are no longer supported. You must use the Caspio built-in event handlers, as described below on this page.

Working on trying to use a Caspio event handler to substitute the onclick function.

Edited by kpcollier
Link to comment
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...
×
×
  • Create New...