Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / November 2005

Tip: Looking for answers? Try searching our database.

insert data into form field using jscript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike L - 16 Nov 2005 00:31 GMT
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.
Franck Dauché - 16 Nov 2005 01:13 GMT
Hi Mike,

If your schema is:
myFields
  fieldname

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

Hope that it helps.

Regards,

Franck Dauché

> Anyone know how to insert values into form fields using jscript? I've tried
> the following:
[quoted text clipped - 16 lines]
>
> None of them work and i'm running out of ideas.
Mike L - 16 Nov 2005 01:22 GMT
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"

> Hi Mike,
>
[quoted text clipped - 30 lines]
> >
> > None of them work and i'm running out of ideas.
Franck Dauché - 16 Nov 2005 01:31 GMT
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é

> Hi Franck
>
[quoted text clipped - 44 lines]
> > >
> > > None of them work and i'm running out of ideas.
Mike L - 16 Nov 2005 01:43 GMT
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?

> Hi Mike,
>
[quoted text clipped - 62 lines]
> > > >
> > > > None of them work and i'm running out of ideas.
Franck Dauché - 16 Nov 2005 02:18 GMT
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é

> Yes, it does work. However, i don't know why it doesn't work in my form when
> it was designed in Infopath.
[quoted text clipped - 68 lines]
> > > > >
> > > > > None of them work and i'm running out of ideas.
Mike L - 16 Nov 2005 02:44 GMT
I've found the solution. My script was missing the following

XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-04T01:51:06" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

Thanks for your help.

> Hi Mike,
>
[quoted text clipped - 86 lines]
> > > > > >
> > > > > > None of them work and i'm running out of ideas.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.