473,804 Members | 3,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic fill form fields depending on dropdown box

Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated
I search all over the web but I could not find it.

Thank you for your help

Alex
Feb 22 '06 #1
19 3996
Alex wrote:
Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated

Are you talking about Javascript here?
Do you want the user to do a select on your page and the page will fill the
appropriate fields? Then go Javascript.

Or do you want to go back to the server if somebody touches the selectbox?
Then it is PHP.
I think you better do this with Javascript.
Try comp.lang.javas cript.

If you want to do it in PHP, well... where to start?
Do you know how to receive a form in PHP? ($_POST[] and the like)
Do you know how to put dynamical data into your html-page with PHP?

If you want to do this in PHP, please be more specific and ask a question
that is answerable instead of the complete solution to a problem nobody in
here knows except you. :-)


I search all over the web but I could not find it.
Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why you
didn't find any code that does similar things.
(No punch intended)

Good luck.

Regards,
Erwin Moller

Thank you for your help

Alex


Feb 22 '06 #2
Erwin Moller wrote:
Alex wrote:
Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated


Are you talking about Javascript here?
Do you want the user to do a select on your page and the page will fill the
appropriate fields? Then go Javascript.

Or do you want to go back to the server if somebody touches the selectbox?
Then it is PHP.
I think you better do this with Javascript.
Try comp.lang.javas cript.

If you want to do it in PHP, well... where to start?
Do you know how to receive a form in PHP? ($_POST[] and the like)
Do you know how to put dynamical data into your html-page with PHP?

If you want to do this in PHP, please be more specific and ask a question
that is answerable instead of the complete solution to a problem nobody in
here knows except you. :-)

I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why you
didn't find any code that does similar things.
(No punch intended)

Good luck.

Regards,
Erwin Moller
Thank you for your help

Alex

Well you are almost right, this is not only php it is also a bit of
Javascript, I need in fact to be able to pass the
$fields=mysql_f etch_object($da taresults} to a javascript, but I do not
see how I can implement that since I do not know how to pass the result
using php, so in that sens it is also php relevant

as for the punch, I searched the net but I only get either trivial
results or things that populate a drop down menu (which I already know
how to do) That's why I ask it here

Thanks
Feb 22 '06 #3
Krustov wrote:
<comp.lang.ph p , Erwin Moller ,
si************* *************** **...yourself.co m>
<43************ ***********@new s.xs4all.nl>
<Wed, 22 Feb 2006 16:46:51 +0100>
> I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why
you didn't find any code that does similar things.
(No punch intended)


Do you ever actually help anybody on here who asks a question .

You only ever seem to comment and give your opinion on 'what' they ask
rather than helping them .


Bull. Look around more.
I do actually help people, even this OP, as you could see in the part you
cutted away. Please go insult somebody else, thanks.

Erwin Moller


Feb 22 '06 #4
Alex wrote:
Erwin Moller wrote:
Alex wrote:

Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated

Are you talking about Javascript here?
Do you want the user to do a select on your page and the page will fill the
appropriate fields? Then go Javascript.

Or do you want to go back to the server if somebody touches the selectbox?
Then it is PHP.
I think you better do this with Javascript.
Try comp.lang.javas cript.

If you want to do it in PHP, well... where to start?
Do you know how to receive a form in PHP? ($_POST[] and the like)
Do you know how to put dynamical data into your html-page with PHP?

If you want to do this in PHP, please be more specific and ask a question
that is answerable instead of the complete solution to a problem nobody in
here knows except you. :-)
I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why you
didn't find any code that does similar things.
(No punch intended)

Good luck.

Regards,
Erwin Moller

Thank you for your help

Alex

Well you are almost right, this is not only php it is also a bit of
Javascript, I need in fact to be able to pass the
$fields=mysql_f etch_object($da taresults} to a javascript, but I do not
see how I can implement that since I do not know how to pass the result
using php, so in that sens it is also php relevant


creating a javascript portion of a page and populating it with the data
from $fields is no different than creating the select/options from a
resultset.

Spend some time to map out your data flow. where does it come from
(server-side database, client-side selection/entry), where does it go
browser/client,server into database or other processing.

as for the punch, I searched the net but I only get either trivial
results or things that populate a drop down menu (which I already know
how to do) That's why I ask it here

Understanding the data flow above allows you to be a good programmer not
just a copy/paster (while that is not bad, you should not rely on it).
One should also understand the technologies they are using and why they
are using them - there may be other solutions to your problem you/we
have not thought of...
Thanks


Feb 22 '06 #5
Krustov wrote:
<comp.lang.ph p , Erwin Moller ,
si************* *************** **...yourself.co m>
<43************ ***********@new s.xs4all.nl>
<Wed, 22 Feb 2006 16:46:51 +0100>
I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why you
didn't find any code that does similar things.
(No punch intended)

Do you ever actually help anybody on here who asks a question .

You only ever seem to comment and give your opinion on 'what' they ask
rather than helping them .


Krustov,

did you ever think that by forcing someone back to the docs or other
research DOES help them to better understand what it is they are trying
to accomplish and maybe - just maybe - learn a lot more than they would
if we just gave some code snippet? (BTW I have seen WAY TOO MANY
questions in some forums that are trying to solve almost an identical
problem - and some in those forums refuse to answer because it is common
knowledge they are trying to solve an assignment from their CIS/IT
professor in school. Solving the problem with a code snippet gains
nothing - understanding the technology gains much knowledge enabling
them to solve more and more complex isssues. Most programmers/IT
professionals are neither programmers or professional... )

I could go on a rant that describes how some generations feel they
"deserve" to be spoon-fed their entire life - but I do not believe this
situation warrants that much effort.
Feb 22 '06 #6
noone wrote:
Krustov wrote:
<comp.lang.ph p , Erwin Moller ,
si************* *************** **...yourself.co m>
<43************ ***********@new s.xs4all.nl>
<Wed, 22 Feb 2006 16:46:51 +0100>
I search all over the web but I could not find it.

Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why
you didn't find any code that does similar things.
(No punch intended)

Do you ever actually help anybody on here who asks a question .

You only ever seem to comment and give your opinion on 'what' they ask
rather than helping them .


Krustov,

did you ever think that by forcing someone back to the docs or other
research DOES help them to better understand what it is they are trying
to accomplish and maybe - just maybe - learn a lot more than they would
if we just gave some code snippet? (BTW I have seen WAY TOO MANY
questions in some forums that are trying to solve almost an identical
problem - and some in those forums refuse to answer because it is common
knowledge they are trying to solve an assignment from their CIS/IT
professor in school. Solving the problem with a code snippet gains
nothing - understanding the technology gains much knowledge enabling
them to solve more and more complex isssues. Most programmers/IT
professionals are neither programmers or professional... )

I could go on a rant that describes how some generations feel they
"deserve" to be spoon-fed their entire life - but I do not believe this
situation warrants that much effort.


thx mate. :-)

Erwin
Feb 22 '06 #7
Alex wrote:
Erwin Moller wrote:
Alex wrote:
Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated


Are you talking about Javascript here?
Do you want the user to do a select on your page and the page will fill
the appropriate fields? Then go Javascript.

Or do you want to go back to the server if somebody touches the
selectbox? Then it is PHP.
I think you better do this with Javascript.
Try comp.lang.javas cript.

If you want to do it in PHP, well... where to start?
Do you know how to receive a form in PHP? ($_POST[] and the like)
Do you know how to put dynamical data into your html-page with PHP?

If you want to do this in PHP, please be more specific and ask a question
that is answerable instead of the complete solution to a problem nobody
in here knows except you. :-)

I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why
you didn't find any code that does similar things.
(No punch intended)

Good luck.

Regards,
Erwin Moller
Thank you for your help

Alex

Well you are almost right, this is not only php it is also a bit of
Javascript, I need in fact to be able to pass the
$fields=mysql_f etch_object($da taresults} to a javascript, but I do not
see how I can implement that since I do not know how to pass the result
using php, so in that sens it is also php relevant

as for the punch, I searched the net but I only get either trivial
results or things that populate a drop down menu (which I already know
how to do) That's why I ask it here

Thanks


Hi alex, just hang on.
I made something similar (databasemappin g to JS) just one week back, and am
fitting it into an example that I will post soon.

Erwin
Feb 22 '06 #8
Alex wrote:
Erwin Moller wrote:
Alex wrote:
Hello list

This question has probably already been asked, but let me ask again

I have a mysql database to which I connect with my php scripts. The
database contains articles. Name, Unit_Price and Reference

Now my client needs to order 5 items, click a button and a table with 5
lines and 3 columns appears (until now easy)

In the first column is a drop down box with a <select > and <options> in
which I store all possible names.

I would like than whenever the client changes one of the boxes (in my
case there are 5) the Unite_Price column and Reference column in the
line he just choose get automatically updated


Are you talking about Javascript here?
Do you want the user to do a select on your page and the page will fill
the appropriate fields? Then go Javascript.

Or do you want to go back to the server if somebody touches the
selectbox? Then it is PHP.
I think you better do this with Javascript.
Try comp.lang.javas cript.

If you want to do it in PHP, well... where to start?
Do you know how to receive a form in PHP? ($_POST[] and the like)
Do you know how to put dynamical data into your html-page with PHP?

If you want to do this in PHP, please be more specific and ask a question
that is answerable instead of the complete solution to a problem nobody
in here knows except you. :-)

I search all over the web but I could not find it.


Really?
This is quite basic stuff (both in Javascript and PHP) so I wonder why
you didn't find any code that does similar things.
(No punch intended)

Good luck.

Regards,
Erwin Moller
Thank you for your help

Alex

Well you are almost right, this is not only php it is also a bit of
Javascript, I need in fact to be able to pass the
$fields=mysql_f etch_object($da taresults} to a javascript, but I do not
see how I can implement that since I do not know how to pass the result
using php, so in that sens it is also php relevant


Ok, clear.
So you need data from the database ready-at-hand in a webpage, usable for
javascript? Right?

Here follows a simple example, maybe enough to get you going in your own
situation.

Suppose you have 1 selectbox, and depending on the value the visitor selects
you need to populate a second selectbox.
eg:
[mainselectbox] category
[secondary selectbox] item

You can now simply fill the first selectbox with appropriate options. (You
said you already know how, so I skip that part)

Just add an eventhandler to the select, you'll end up with something like
this (just the html)
<select name="mainselec tbox" onChange="popul ateSecondairy() ;">

Here follows a comple example.
I faked the queryresults to keep things shorter, but if you understand the
used Javascript, you are able to modify it for your own uses.

------------------------------
<?

// fakeresult from databasequery that returned category and items
$rs = array(
"fruit" => array("apple"," banana","pineap ple"),
"books" => array("HitchHik ersGuideToTheGa laxy","Programm ing
Perl","Postgres ql"),
"animals" => array("dog","ca t")
);

?>
<html>
<head>
<title>test</title>
</head>
<body>

<form action="bla.php " Method="POST" name="testform" >
category: <SELECT name="category" onChange="popul ateSecondSelect ();">
<?
foreach($rs as $cat => $items){
?>
<OPTION value="<?= $cat ?>"><?= $cat ?>
<?
}
?>
</SELECT>
<hr>
Item: <SELECT name="item">
<OPTION value="-1">pick category first
</SELECT>
</form>

<script type="text/javascript">
// drop all possible item-values in Object
var category = new Object();

<?
// Create all js-object with their items
foreach($rs as $cat => $items){
// put all $items in JS-readable format.
$JSitems = "";
$itemsWithQuote s = array();
foreach ($items as $oneItem){
$itemsWithQuote s[] = "\"$oneItem \"";
}

?>
category['<?= $cat ?>'] = new Array(<?= implode(",",$it emsWithQuotes) ?>);
<?
}
?>

function populateSecondS elect(){
// get selected category
var selCat = document.forms["testform"].category.selec tedIndex;
var catName = document.forms["testform"].category[selCat].value;

// now repopulate the second selectbox
var refSecond = document.forms["testform"].item;

// remove old options
refSecond.lengt h = 0;

// add new options
var theArr = category[catName];
for (var i=0; i< theArr.length ; i++){
refSecond.optio ns[refSecond.optio ns.length] = new
Option(category[catName][i],"hai");
}

}

</script>

</body>
</html>
--------------------------------------
Hope that helps.

Good luck,
Erwin Moller
Feb 22 '06 #9
Krustov wrote:
<comp.lang.ph p , Erwin Moller ,
si************* *************** **...yourself.co m>
<43************ ***********@new s.xs4all.nl>
<Wed, 22 Feb 2006 17:35:57 +0100>
> Do you ever actually help anybody on here who asks a question .
>
> You only ever seem to comment and give your opinion on 'what' they ask
> rather than helping them .
Bull. Look around more.
I do actually help people, even this OP, as you could see in the part you
cutted away. Please go insult somebody else, thanks.


Yes i'd say you do help some people .

But would you say that grants you the right to spout drivel at others .


drivel?
Well thanks.

If you don't care for my postings, I suggest you put me on your blocklist. I
couldn't care less.
Most posters I answer appreciate my effort. If you don't: fine with me.

If, however, you don't like my tone, and want to educate me on that: fine
too, really, point taken.

I am here to help people and get help, not to socialize.


No big thing and not the end of the world - but perhaps your forgetting
its not just the person you are replying too that sees it .


So what?
Do you think I am not aware of that?

Seriously: If you think that I for some invalid reason was rude: Sorry for
that. But I don't think I was out of line somewhere.

I am trying to help people in here, and when I see bad questions (which I
see a lot lately) I get irritated.
It seems less and less people know how to post in usenet these days.

Regards,
Erwin Moller
Feb 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7406
by: 35th Ave Media | last post by:
Hello, I have about 60+ pages that I need to insert a MAILTO: tag so people can email the page using their email client. The body of the message is going to be the URL of that page. Using ASP, how can I insert the page URL in the email body without having to manually enter each URL for each MAILTO: tag? Is there a variable that can be used inside the MAILTO: tag that automatically inserts the current page's URL into the body of the...
0
1131
by: Anthony | last post by:
So I've got three dropdowns in a datagrid footer (to add records). I need them to cascade, in the first one I have three choices, in the second one I have anywhere from 3 to 10 choices, depending on what is selected in the first one, etc, etc. Whats happening is that when the auto-postback occurs, it fires the event for the dropdownlist change, which calls the Getxxx routines that update the dropdownlist's datasource to the new datatable...
2
1416
by: Woody Splawn | last post by:
I have a question about technique with regard to filling drop downs. I have a Winform that has several different tabs and tables associated with it. In an effort to keep the load time small I would like to not fill the fields with lookups at form load time. I have a grid on a tab of this form that has six fields in it that have lookups associated with them. By lookups I mean that the dropDown in the field is populated by doing a query...
15
2014
by: firstcustomer | last post by:
Further to my earlier post, I've found something that does partly what I'm doing, but there are two issues: 1) There is an error in the script. Being a Javascript newbie, I've no idea what the problem is. 2) I don't know how to re-program the script so that it opens up a url depending on the choices made. Here is the code (thanks Google!), I'd appreciate any help the you can
1
1921
by: phpnewbie2007 | last post by:
I have 2 dynamic PHP dropdowns: The second dropdown populates from the first, depending on what is selected in the first. The page is showing issues in a department: The first dropdown consists of departments- It has 3 options All issues, dept A, dept B If dept A is chosen in the first dropdown, the second dropdown shows all members in dept A and all issues are shown for dept A are shown below. Now if i choose a member in second...
1
4665
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3504
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
1
1946
by: =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?= | last post by:
Hi I have been banging my head for a few days now with this issue. I have a page that has several update panels everything is working fine except for 1 thing. I am creating a sort of wizard that will build a form that I plan to save to a database On stage 2 I load a usercontrol an unspecified number of times depending on
1
3482
by: bytesFTW99 | last post by:
I have been struggling with this for some time can anyone help out? just trying to have 3 dropdown boxes that fill depending on what is selected, then in some cases click a button and have the second set of 3 dropdown boxes be filled with the same values. thank you <head> <SCRIPT LANGUAGE="JavaScript" type="text/javascript"> var firstChoice2 = 0; var secondChoice2 = 0;
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10070
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.