insert data into form field using jscript

M

Mike L

Anyone know how to insert values into form fields using jscript? I've tried
the following:

var formField = XDocument.DOM.selectSingleNode("fieldname");
formField.text = "123";

I've debugged the code and added a watch on variable formField but it always
gets the value null even though it contains a default value.

I don't think i'm referencing the form field correctly but I've also tried:

/my:myFields/my:fieldname - gets an error saying that "my" is not recognised
/myFields/fieldname
//fieldname
/fieldname
../fieldname
.../fieldname
/Main/myFields/fieldname

None of them work and i'm running out of ideas.
 
F

Franck Dauché

Hi Mike,

If your schema is:
myFields
fieldname

Then, use: "/my:myFields/my:fieldname"

Hope that it helps.

Regards,

Franck Dauché
 
M

Mike L

Hi Franck

I have tried your suggestion but i get the following error:

"A run-time error has occurred.
Do you want to debug?

The following error occurred:

Reference to undeclared namespace prefix: 'my'.

File:script.js
Line:39"
 
F

Franck Dauché

Hi Mike,

To make sure that we are talking about the same thing (schema-wise), can you
please create a new blank form in InfoPath. Drop one textbox on the form.
The schema will be:
myFields / field1
Put a button and put:
var formField = XDocument.DOM.selectSingleNode("/my:myFields/my:field1");
formField.text = "123";

It will work.
Now the question is: were did you get you schema? did you design it outside
InfoPath?

Regards,

Franck Dauché
 
M

Mike L

Yes, it does work. However, i don't know why it doesn't work in my form when
it was designed in Infopath.

Do you know how i can resolve this problem without having to recreate the
form from scratch?
 
F

Franck Dauché

Hi Mike,

probably 1 of 2 solutions:
- your schema was corrupted.
- your schema was designed outside IP and is using a different namespace.

If you are willing to investigate:
Go in design mode, Go to File / Extract Form Files
open template.xml and look at the namespace at the root: is it <my:myFields?
You can do it with your new form (that does work) and you can compare:
manifest.xsf
template.xml
and look for namespace issues/differences.

Regards,

Franck Dauché
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top