I am trying to capture a value when a visitor to the site selects a value from a scroll. I want to captuer that value when they click the submit button on a form.
The website is http://atlanticbay.com/douglasmoran/ You will see form at bottom of page, the Scroll is title
“how can we help you?” <—The value they select here is what I want to capture.
Here is the JQuery I tried along with other, but this was my final effort.
You mean that select with the ID input_1_7? You’re probably thinking way too complicated then. :-) You can get the value of the selected option simply by the value of the select element, like
Ok so i want the value that they select, but i can’t capture it until after they click submit. SO i want the value in the field after they changed it. What ever it may be at the time they click submit.
What exactly did not work? I just copy/pasted that snippet into the console, and when I click the “send” button it logs the value of the currently selected option as expected.
However, if you want to get that value right when the option is selected, you’ll need a change event listener as @DaveMaxwell suggested. There are no changes to the markup necessary either way. (Did anybody maintain the contrary?) ^^
Ok so I tried to do the same thing, I copy paste the snippet into the console and then clicked send. I don’t see a console log of the value. If i fill out the form and then click the submit button after copy paste snippet into console… this is what I see…
// Do something with that value
});
[<form method="post" enctype="multipart/form-data" target="gform_ajax_frame_1" id="gform_1" class="mb-contact-form" action="/amieecarr/#gf_1">…]
SATELLITE: detected tabfocus on #document
SATELLITE: detected click on INPUT
SATELLITE: detected submit on FORM
SATELLITE: detected elementexists on DIV
Well that’s not the snippet I posted above. ;-) First of all, you didn’t declare satelite, which would actually yield a reference error; and then you didn’t log the result, so of course there won’t be any output. Also, don’t fill out the entire form, as any console output will disappear if you get redirected; just select an option and click “send”.
I think I know what the problem is. When the form is completely filled out and the visitor click on the submit button, the form is changed before the script could capture the option selected. That is why I can’t capture the value even though the script works. I need to find a way to capture the value before the form is changed when the visitor click on the submit button.
So I assume you don’t have access to the original submit handler which does evaluate and eventually change and submit the form? It depends at which point you need to process those input values then… one possibility would be aforementioned change event listener, which updates _satelite.getVar each time an option gets selected.
Another option would be to prevent the default event when submitting the form, do something with the value, and when everything is done remove the submit handler and trigger another submit event on the form; however this is likely to interfere with the original site logic, which appears to be pretty involved. Anyway, it really depends on what you’re trying to do with that value.