Code to copy text from a Textfield to a web form - Can this be done?

I have a Window with a Tabbed control. On one tab I have a few Textfields that get populated from a data source. On another tab I have a HTMLviewer that displays a URL which is a fillable form (it’s a SurveyMonkey form).

Is there a way to programmatically transfer (copy/paste or ?) data displayed in the text fields to specific fields on the Surveymonkey web form?

Currently I have Buttons for each text field that allow the user to copy the text to the clipboard and they can do a simple paste on the Surveymonkey form but they have to do them one at a time. While that is not a big issue, it does leave it open to user error whereby they paste the wrong info sometimes. I’d like to eliminate that somehow by having one button that will transfer all necessary fields of data to the appropriate fields on the Surveymonkey form.

If so, can anyone point me to some code example or suggest how to code it.

Thanks

So you’re forging your SurveyMonkey results? Doesn’t that defeat the purpose?

Anywho, if you know the IDs of the fields you can set their value with ExecuteJavaScript.

ExecuteJavaScript("document.getElementById('%fieldID%').value = '%myValue%';")

Where %fieldID% is the id of the field on the webpage, and %myValue% is the value you’d like to insert. Remember to escape the value so that it doesn’t break the javascript should it contain a single quote, linebreak, or the like.

[quote=253782:@Tim Parnell]So you’re forging your SurveyMonkey results? Doesn’t that defeat the purpose?

[/quote]

Thanks Tim, I’ll give that a try.

No, not forging at all. The user either has to copy from each text field on the first tab and paste it at a corresponding field on the Surveymonkey form. ie. LastName -> LastName; WorkOrderNumber - > WorkOrderNumber and so on. What happens is they might get the LastName into the WorkOrderNumber field on the Surveymonkey form without noticing it. The results of the Surveymonkey come back to me for processing and reporting and I wind up having to FIX their mistakes.

OK, checked into that but each new Surveymonkey form, the fields have different IDs.

FWIW, we receive data from a client, do the Survey and fill out the form for each record in the data set. This would be known as Week1 as an example.

Then Week2 data arrives and a new Surveymonkey URL is created. We do this over and over for each week of the year. Each week’s data set might contain 200 - 600 records (aka surveys).

SurveyMonkey seems to have a REST API. Perhaps that could be used to fill out survey forms using your own info.

Thanks Paul, I’ve looked into that [some] … appears too complicated for my needs. I’m thinking there’s no simple method of doing this other than what I’ve already got. Guess I’ll just have to ‘crack the whip’ on our agents to be more dilligent.

Check http://www.w3schools.com/jsref/met_document_getelementsbytagname.asp

For 200-600 records I would look more into that API.

[quote=253782:@Tim Parnell]So you’re forging your SurveyMonkey results? Doesn’t that defeat the purpose?

Anywho, if you know the IDs of the fields you can set their value with ExecuteJavaScript.

ExecuteJavaScript("document.getElementById('%fieldID%').value = '%myValue%';")

Where %fieldID% is the id of the field on the webpage, and %myValue% is the value you’d like to insert. Remember to escape the value so that it doesn’t break the javascript should it contain a single quote, linebreak, or the like.[/quote]

Tim, I’m trying to get this to work but keep getting an OLEexception error. Specifically what is ‘document’ … is that a generic example whereby I need to put the real reference or???

I don’t know if that’s causing the error or exactly what.
Do I need the % signs?

Thanks

document tells JavaScript to refer to the document. There are other reserved words like window as well. The % signs are just my form of placeholder.

If the element does not exist you’re going to get a JavaScript error, which raises an OLEException.

Can you post the code you’re actually using?

[code]dim sShopName As string
sShopName=txShopName.Text

SMviewer.ExecuteJavaScript(“document.getElementById(’%926711946_9964075414%’).value = '%” + sShopName + “%’;”)[/code]

“926711946_9964075414” is the ID in the html of the Surveymonkey document.

SMviewer is the name I gave to the HTMLviewer

I get that from the source …

            Shop name
        </label><input id="926711946_9964075414"
               name="926711946_9964075414"
               type="text"
               class="text"
               
               size="50"

Yeah, lol, the % are just what I use for placeholders. I can glance at them and know it’s a placeholder :stuck_out_tongue:
Take them out of your code and it should work.

[quote=253875:@Tim Parnell]Yeah, lol, the % are just what I use for placeholders. I can glance at them and know it’s a placeholder :stuck_out_tongue:
Take them out of your code and it should work.[/quote]

Yup… it works! Thanks so much! you da man!