Solved

Determining value of secondary input based upon primary

Posted on 2016-08-18
2
28 Views
Last Modified: 2016-08-31
Okay, so I've got a stupid question.  Here's a model of what I'm working with.

https://jsfiddle.net/5bxjxwj4/2/

There's a webform that's dynamically created based upon database entries (course 1, course 2, ... course X).  The user selects the a number of tickets based upon the select next to the price.

What would be the best way of determining which price has been selected on form submission?
0
Comment
Question by:erzoolander
2 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
First problem - duplicate id's - id's must be unique on the page.
Second problem - duplicate names - the second one will overwrite the first ... actually the submission will be something like
adnum_1=4&adnum_1=2

Open in new window

But even if you process the raw POST you can't tell which is which.

Just give your selects different names like
adnum_68 and adnum_70
That way you can check the values of those variables when they are submitted to see how many of each ticket was requested.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
A general design for something like this would be a "Course Object."  This object would live in your database (probably in an active record design).  Each Course would be represented by one object.  The object would have associated information about the course, for example, its "id" and title, cost, duration, schedule, number of seats, number of available seats, etc.

The PHP script that builds the HTML form would use the Course Object to create the HTML.  Since the course "id" is unique, it can be used as a suffix for the form input control names.  This will give you a way to get names like adnum_68  and adnum_70  as Julian suggests.

If you're getting into course and class scheduling, the fundamentals of a "resource scheduling calendar" will come into play.  This article contains an example showing the design we use to schedule finite resources.  See Practical Application #12.
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now