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

Ajax and Javascript Issues

Thread began 8/21/2022 1:35 pm by yogastudents362523 | Last modified 8/24/2022 10:14 am by Ray Borduin | 92 views | 10 replies |

yogastudents362523

Ajax and Javascript Issues

Hello,

I have created a 3-part Country/Region/City menu set that works well upon the page.
As soon as an individual selects a country (USA) on the country menu, then the next menu immediately opens up with all available US States. And then as soon as the person selects California, the City menu populates with all citities in California, and they can select "Carlsbad". I found databases to drive it and linked them together, and this now works all over the world.

However, because I do not know any Ajax or Javascript, I am unable to work out (from the pieces of code I picked up in various locations off the Internet) how to get the chosen country, region, and city to enter my database when the submit button is pressed.

I have placed the URL for a working page in the upcoming private area, and also attached the files that make it work.

I will convert them all into friendly webassist format and queries because those are reliable, but I have at present left all the coding alone as I found it, and graduallyh engineered it together to make everything work.

I will understand if you do not have the time or inclination for this, and will then simply revert to my previous method of getting everyone to simply write in the necessary information. But as I think you can see, the demo page is simply slicker and more bulletproof, and works for all countries, regions, and citiies worldwide.

Thank you.


But I am unfortunately unable to take the final step.

I am again looking for the method to gather up the data in a form, and submit it to the database, and preferably through your mySqli Update routines. Thank you.

Attached Files
z_cities-by-state.php
z_index.php
z_states-by-country.php
Sign in to reply to this post

Ray BorduinWebAssist

Just give your <select> elements a name attribute and then they will be included in a form submit just like any other form element.

Sign in to reply to this post
Did this help? Tips are appreciated...

yogastudents362523

Thank you.

I again feel idiotic. The first thing I tried was using the select names, but they had id="somename", which I thought was sufficient. I have now gone and given them all the name="somename" attribute.

That of course only inserts the id numbers into the table, but that is an easy fix with a "before page load" query on the one I load immediately after.

Thank you

Sign in to reply to this post

yogastudents362523

I am now having trouble with a follow-up page, which should allow Presenters to update their information, but using these same dependent menus.

I have used the following code snippet on that page, and it works well enough in that it sets the first field in the dependency set, of Country, to the correct value:

<option value="<?php echo $row['id'];?>" <?php if(($rsAllPresenterData->getColumnVal("CountryID")) == $row['id']) echo ("selected");?>><?php echo $row["name"];?></option>

However, neither of the two succeeding dependent fields works. And nor does it matter if I adjust the option strings to correct values.

I have tried all sorts of tricks with queries and cookie and session variables, but am beginning to suspect that it is not possible in PHP alone.

Is there any way that either Ajax or Javascript would allow all three fields to load up the current values, yet still allow the dependency menuing system to work properly? Or should I just give up and let people hand-correct if they need to? I would prefer to avoid that, however.

Thank you.

Sign in to reply to this post

yogastudents362523

WORKAROUND FOUD

This post has been deleted.

yogastudents362523

I thought I had found a workaround. But it in fact deletes the relevant data.
So I deleted the last post.

Still searching for an updating solution.
Thank you.

Sign in to reply to this post

Ray BorduinWebAssist

I think I need to do screen sharing with you to figure this out at this point... or at least give me a url and steps to reproduce your issue so I can see what you are working on and what is and isn't working correctly. I'm sure it can be done, but I'm not sure where exactly you are going wrong.

Sign in to reply to this post
Did this help? Tips are appreciated...

yogastudents362523

Thank you.
I will try you tomorrow, Tues, after 2:00 pm.
I will also upload my efforts.

Must go

Sign in to reply to this post

yogastudents362523

Hello,

(Apart from a very minor wrinkle)

I now have a working system.
It is probably very clunky in your eyes.

I load the first page given in the underneath URL.

That then allows Presenters to use the descendent menus to choose a new Country, Region, and City.
When they hit "Update", the ID values are placed in the fields NewCityID, NewCountryID, and NewRegion1ID.

Pressing the update button also immediately takes Presenters to the followup page (also given underneath).

That page then has 9 MySQLi scripts as follows:

UPDATE presenter_data
SET presenter_data.CountryID = presenter_data.NewCountryID
WHERE
(
presenter_data.NewCountryID IS NOT NULL);

UPDATE presenter_data
INNER JOIN countries ON ( presenter_data.CountriyID = countries.id )
SET presenter_data.Country = cities.`name`;

UPDATE presenter_data
SET presenter_data.NewCountryID = NULL
WHERE
(
presenter_data.NewCountryID IS NOT NULL);

I then repeat each of those in separate MySQLi queries for Region1ID and CityID.

This may be a long roundabout way, and it is probably more elegant with Javascript and/r Ajax, but this is now working.

Thank you.

Sign in to reply to this post

yogastudents362523

Need way to reload/refresh page

Sorry

The minor wrinkle is that I need to find some way to refresh the page when I am done.
I am sure there is a method using either PHP or Javascript.

I will look at some of your other extensions to spot the way you do it, when I have time later.

I have to go and teach right now, so it will have to wait.

Thank you so much again for your tools.

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...