Jump to content

Set Contact Form field value from javascript

Recommended Posts

Hi to all! I'm trying to set a value in a contact form field, but I'm having troubles.

In facts, it seems that I can set the value, with this instruction:

$('#text-1066fdb2-1602-44d4-9cdb-69681a16189a-field').val("ok").change();

I see the value in the textbox changing, but when I press the button to send the form, the value disappear. It seems that I'm not changing the real field, but a sort of link of it. 

How can I really set the value of the field? Is it possible?

thanks a lot

Stefano.

Link to comment
  • Replies 2
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

40 minutes ago, StefanoM2 said:

I'm trying to set a value in a contact form field, but I'm having troubles. It seems that I'm not changing the real field, but a sort of link of it.

Form Blocks are now built using React. In React, for every DOM object, there is a corresponding virtual DOM object so, as you mentioned, changing the DOM won't change the form itself. To do this, you'll need to tell React that there's been a change. See earlier threads for more background. 

Did this help? Please give feedback by clicking an icon below  ⬇️

About me: I'm Paul, a SQSP user for over 18 yrs and a Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL, providing high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji below. Buying a coffee is optional.

Book paid help with domains: Connect a GoDaddy domain. Connect a Squarespace Domain. Domain assistance

Link to comment

Thank you for your prompt reply ... I tried the code, everything seems correct, via "console.log" I see correct values, the field doesn't change until a "human" enter value manually in the field.

I think I understood the example of codepen:

https://codepen.io/anulesh91/pen/XGwZoR

and it works, but in squarespace form it doesn't. Any ideas?

At least, what I'm trying to do is simply trap 2 additional controls in a form, for example: range of dates, range of hours. I'm not able to "prevent" the form submission in any way (button is not "prevantable"), so I was trying to have a hidden field mandatory, to fill with a value only when my custom controls are ok. That's quite simple, but squarespace doesn't permit me to customify almost nothing 😞

If you have any ideas and / or advices i would appreciate very much.

 

thanks

Stefano.

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.