Jump to content

Send/Receiving & Inputing the Same Data


danscreations

Recommended Posts

I have a simple script that includes three dropdown menus all which have their own form (Make, Model, Year; in that order). Once Make is selected that form submits to the same page obviously passing it's value. The Model menu is then enabled and works the same as the previous (Make) menu but has a hidden value which is "Make" and will include its value and so on. Very simple structure but the issue is the page needs to be refreshed each time to pass these variables and there values.

 

I've looked over several tutorials, etc, and can't find exactly what I need.

 

Basicly want to send the forms to a new php that will have all three variables for the dropdown menu (Make, Model, Year), receive them, and then place all there values where they belong in the forms. Basicly the same thing it does now just with a PHP/Ajax script in the background so the page doens't have to reload.

 

I'm not sure how to define all these variables, have the php script assign them, receive them, and then place them where they need to go. Anyone know?

Link to comment
Share on other sites

Another option would be having the options from the beginning, and having javascript populate the next fields.  This depends on how large your dataset is, and how good you are at js.

 

Otherwise, you would use ajax to send the values just as you would with the form.  There are plenty of tutorials out there for ajax... after you try it, if it still doesn't work, post your code, and specifically what is not working.

Link to comment
Share on other sites

Another option would be having the options from the beginning, and having javascript populate the next fields.  This depends on how large your dataset is, and how good you are at js.

 

Otherwise, you would use ajax to send the values just as you would with the form.  There are plenty of tutorials out there for ajax... after you try it, if it still doesn't work, post your code, and specifically what is not working.

 

Well broke down due to not being able to find out exactly what I needed. With the help of the book I figured out how to send the data and return it. The issue is that the traditional way of resubmitting the same data using php by refreshing the page made me build the dropdown menu's based off the submitted data. So I can send data back and forth all day long using AJAX but I can't figure how to get the dropdowns to update. Any Ideas?

Link to comment
Share on other sites

You can use javascript to populate the innerHTML of the <select></select> options you want to change/populate.  The innerHTML would most likely be the ajax response.

 

-Drop Down one: [Make1] -> sends make to php page in the background

-  php reads it, says there are these models for that make, outputs html as plaintext:

-  <option value="model1">Model 1</option>

  <option value="model2">Model 2</option>

 

-Javascript takes that responseText and places it into the innerHTML of Drop Down two;

-User chooses a model from Drop Down 2, process repeats with php displaying the years available, javascript populates the third dropdown.

 

-User selects something from third drop down, year.  Perhaps then the page is submitted as "make, model, year" to ensure quality and retrieve results.

Link to comment
Share on other sites

Thanks for the replys....I'm a little fustrated at this point. I tried something very simular but with the entire dropdown getting populated instead of just it's contents or selection. What you suggested does make since though. Would you suggest to have each dropdown menu have it's own php page to generate the options or make one that does it all depending on the selected input? Also in your final statement you noted I might want to send the page....something like this?

 

Make (AJAX)

Model (AJAX)

Year (pagename.php?make=whatever&model=whatever&year=whatever)

 

One thing that I'm either trying to understand with AJAX or confused on how to pass it is not only the menu generation but being able to retrieve the submitted selected and reusing it for the next dropdown. In the orignal script I made each dropdown was it's own from and as the page was resubmitted the submitted data was inputed into the next form. Example:

 

Make Dropdown (input) > submit (page.php?make=whatever)

Model Dropdown (input) + Make (hidden with make=whatever value) > submit (page.php?make=whatever&model=whatever)

etc, etc, etc.

 

So naturally what I'll want to do is have the same system setup but sent using AJAX generating the menus and then sending the menu back along with the selected input. I have yet to do this and figure out once I have it how to get it assigned into the next form in the hidden field(s).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.