Page 1 of 1

Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 1:25 am
by rongreen
I have a Radio button called "clear". What I want to accomplish is when it is selected it clears specific fields, that is set them to their intial values. Is this possible by setting up conditions, or will this require a custom script? If it can be done by the former, how would I achieve this, setting up where? If it requires a script, is the some wbs example I could be pointed to? Thank you.


https://www.greensphotoimages.com/clearselectfields.zip

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 2:16 am
by BaconFries
Yes it is possible, there is no wbs example file, it is not specific to the software in anyway and yes it will at most require a "custom" script using the likes of javascript/jquery.

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 4:37 pm
by rongreen
Is it possibly to use the AI option to write some or all of the script? I also may have my son-in-law, who is a programmer, to potentially assist(?). In terms of my learning JavaScript, I am up in the senior years and and it may be a challenge, but I plan on trying. I have been out of IT and programming for at least 40 years. So my knowledge base is quite antiquated.

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 5:07 pm
by BaconFries
Is it possibly to use the AI option to write some or all of the script?
It may be possible using AI if you word it correctly. Here is some javascript for you to try. You will need to change field1 and field2 to match the ID of the editboxs to its own
Insert between the <head></head> tags in Page HTML

Code: Select all

<script>
function clearFields() {
  // Get references to the form fields to be cleared
  var field1 = document.getElementById("field1");
  var field2 = document.getElementById("field2");
  // Clear the values of the specified fields
  field1.value = "";
  field2.value = "";
}
</script>
You can also add further lines of such as var field3 = document.getElementById("field3"); but replacing with the appropriate ID to match the editbox.

You will also need to add the following as an event to the radio button using onclick

Code: Select all

clearFields()

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 5:26 pm
by rongreen
Thank you very much. That is extremely helpful. Just to clarify, field1 and field2 are the names of the fields I want to clear, correct? Is the replacement the ID (e.g. PatternItem1Select), or its "name" (e.g. CustomPattern1)? Thank you again for your help!!

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 5:32 pm
by BaconFries
Just to clarify, field1 and field2 are the names of the fields I want to clear, correct? Is the replacement the ID (e.g.PatternItem1Select)
Correct it is the ID

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 5:41 pm
by rongreen
Sorry to be a pest, but I am in the Radio Button choosing Add Event and I selected onclick for the Event, but under action I don't see Select All. Can I trouble you for some further clarification?

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 6:03 pm
by BaconFries
Not at my PC. The action is just javascript as shown in the example screenshot replacing where it says YourFunction() with clearFields()
Image

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 6:10 pm
by rongreen
Thank you! Do I need to specific a target? It appears the HTML you supplied takes care of that, correct? Finally, just to make sure, nothing goes within the parantheses, right?

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 6:25 pm
by BaconFries
No to both

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 7:37 pm
by rongreen
Can I ask you one more thing? The clear is working great, but it removes the text from the field being cleared (e.g. Seclect Pattern" and leaves it blank. How can I repopulate them? It tried PatternItem1Select.value = 'Select Pattern' and PatternItem1Select.value = "Select Pattern", but that was not successful.

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 8:37 pm
by BaconFries
The clear is working great, but it removes the text from the field being cleared (e.g. Seclect Pattern" and leaves it blank.
But isn't that you wanted?, didn't you ask that you wanted to clear specific fields?, what did you expect to happen?

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 8:44 pm
by rongreen
Yes, it is clearing the customer's choice, but in the field it left it blank. However, before they chose out of the long list of options it had text that said "Select Pattern". I just need to repopulate it so they know what the field is about. Because it is a Select it Does not offer a "Place Holder" option.

Re: Possible to use Radio Button to clear specific fields

Posted: Wed Dec 18, 2024 11:12 pm
by rongreen
Maybe what I really need, if even possible, is a field reset or refersh instead of clear?

Re: Possible to use Radio Button to clear specific fields

Posted: Thu Dec 19, 2024 12:13 am
by BaconFries
However, before they chose out of the long list of options it had text that said "Select Pattern".
If you are referring to select/option why do you wish to "clear" this it isn't logical it's purpose it to allow the user to select from a list as you mentioned so why try to clear it? For other "Fields" I can but...
Maybe what I really need, if even possible, is a field reset or refersh instead of clear?
This can already be done by simply adding a "Reset" button to the form but this will "Reset" all fields.

Re: Possible to use Radio Button to clear specific fields

Posted: Thu Dec 19, 2024 2:09 am
by rongreen
I am going to wait until tomorrow so I can give you an explation that will I believe will help make things more clearer. I will also add a demo project file as required. However, if I wanted to add a form reset/clear when the form is loaded on the customer's end where would I put the code? And, is this correct:
document.getElementById("orderformlayoutgrid").reset();

Re: Possible to use Radio Button to clear specific fields

Posted: Thu Dec 19, 2024 6:34 pm
by gofrank
This should be as simple as:

Code: Select all

field1.value = "Select Pattern";
field2.value = "Select Pattern";
Instead of clearing the field, you're just replacing the content with the original prompt.

Re: Possible to use Radio Button to clear specific fields

Posted: Thu Dec 19, 2024 9:09 pm
by rongreen
Thank you gofrank!