close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Autocomplete fields based on Select value?

Thread began 4/26/2012 8:08 am by gary.brett434358 | Last modified 4/27/2012 11:09 am by Jason Byrnes | 2113 views | 12 replies |

gary.brett434358

Autocomplete fields based on Select value?

Hi there, using DA I have insert forms to add contacts & orders to my database. On insert_orders.php I have a select field where I can choose a contact to bind to the new case which works well.

Is it possible once the contact is selected multiple other fields could be hidden as they already exist in database; address, postcode, telephone etc?

I am trying to do away with insert_contact.php, allowing users to either select existing contact or create a new one & bind to case within one form.

insert_case.php

If contact exists then -
SelectFld1 - Search for existing client and hide other contact related fields on form

If contact doesn't exist then -
InputFld1 - Contactname [autofill or manual]
InputFld2 - ContactPhone [autofill or manual]
InputFld3 - ContactPostCode [autofill or manual]
InputFld4 - ContactAddress1 [autofill or manual]
InputFld5 - ContactAddress2 [autofill or manual]

I am sure its not the right way but could I perhaps use SA 'show region' saying if SelectFld1= NULL then show InputFld1, InputFld3 , InputFld3 etc etc

Kind regards for your help once more.

Gary

Sign in to reply to this post

Jason ByrnesWebAssist

this is going to take some extensive hand coding to accomplish, and is not supported.

could probably do it using an ajax call that would take the ID of the selected contact, query the contacts database, then populate the fields with the contact information.



quick google search of:
ajax populate form fields

returned this tutorial that seams to match what your trying to accomplish:
popform.php

Sign in to reply to this post

gary.brett434358

Hi Jason, thanks for the tip.. I had a look earlier at various jquery & ajax options but ran into a problem where DA tried to insert the client twice..

If I searched for contact as per that demo it finds and populates the fields correctly but when I submit the form it tries again to insert the contact then the case.

On this form I am effectively inserting records in 2 tables, contacts & cases which is correct when the contact doesn't exist. The issue I have is the insert runs if I manually type the contact or it pre-populates from select field..

Cant figure out a way to tell it not to insert contact if they already exist..

Thanks again.

regards

Sign in to reply to this post

Jason ByrnesWebAssist

create a hidden element that has a value by default and have the ajax script reset that elements value to be blank.

then in the insert behavior for the client, click the lightning bolt next to trigger and select the hidden element.

this will cause the insert to trigger only if the hidden element has a value. since the ajax script clears it's value, it will prevent the insert.

Sign in to reply to this post

gary.brett434358

Hi Jason, thanks again I tried that but didn't work as the insert cases was binding to a session created when the contacts record was inserted.

No problem it was getting a bit complicated so I decided to simplify it [I thought] by creating a tabbed interface allowing the user to select whichever form suits.

1st tab - insert new contact & case
2nd tab - insert existing contact & case

Both of these forms insert data to 'insert record [tblcases]' & 'insert record [tblcontacts]' with trigger on each insert as 'any form post'

The form in tab2 works no problem, case is inserted attached to correct client. The form in tab1 inserts the new contact and case but doesnt bind the contactid to the case. I am guessing this is because its also submitting the 2nd forms contact data, does that sound correct?

Would I need to duplicate my insert record behaviours and assign each form to trigger only when that forms submit button is pressed?

Thanks again, will post back if I resolve..

Sign in to reply to this post

Jason ByrnesWebAssist

the problem is that you are using any form post for the trigger.


since you are using 2 form on the same page, you will 2 sets of the insert record behavior.

one set for the 1st tab - insert new contact & case the inserts for the contact and case tables should use the submit button for the form on the first tab as the trigger.

the second set for the 2nd tab - insert existing contact & case. these inserts will use the submit button for the second form as the trigger.

Sign in to reply to this post

gary.brett434358

Hi again Jason,
Can I just copy/paste the existing insert code renaming to insert_contact_tab2 for example then setting the button trigger or would I need to use the wizard to do this? I am trying to copy but cant see where the form is linked to the code anywhere?

Cheers

Sign in to reply to this post

Jason ByrnesWebAssist

copy and past will lead to all sorts of issues, it's better to add the server behaviors from the server behaviors panel. click the plus button and select DataAssist -> Insert -> Insert Single Record, repeat this for each one.

Sign in to reply to this post

gary.brett434358

Thanks Jason, reason I suggested it was the DA wizard keeps creating the insert with identical name to first, hence I have 2 x 'insert record [tblContacts]' does it matter?

Each has different session value & trigger points but I cant find anywhere in the code to actually change th name that appears in behaviours panel..

Cheers

Sign in to reply to this post

Jason ByrnesWebAssist

yes, the server behavior names will be the same, this is normal behavior. as long as the triggers are different it does not matter.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...