hi
i want to know that how to get the value of product when select from sub menu
example:
if i select Snack from drop down menu it shows it’s value in next column automaticaly by fetching it from database
plz help me urgentely
Well, if the “Snack” drop-down is created from the database, just assign the value to the drop-down.
Then, you can just display that value.
Snack
Beer
Pretzel
Then, you can use the value and use Javascript to move the value of the SELECT (selected item) to a field.
Otherwise, you would have to use JQuery to poll the database and get the needed data. Another possible way would be to use a PHP file and load it by JQuery dynamically. This works well, but is a lot of work just to get a value that you can place right into the SELECT OPTION’s… Hope that made sense…
bro if i assign the price as value of snacks the how do i get that which item is selected on submission
This is a SELECT drop-down. When selected from the list in the drop-down, the VALUE of the drop-down is whatever you have placed in it.
Snack Beer PretzelOnce posted, this value is available with normal processing. In PHP it is done like this:
<?PHP $somevariable = $_POST['Somename']; echo $somevariable; ?>Whichever item from the drop-down that I called “Somename” would be assigned the VALUE of whichever was selected. So, if the user selected “Pretzel” in the example above, the VALUE of the drop-down would become “.99” which can be used in your code.
Did that make sense to you? Hope so. Good luck, let us know if it didn’t solve it for you…
bro dont mind but i think you did not understand my question or i m not able to make you understand
You originally asked:
hi i want to know that how to get the value of product when select from sub menu example: if i select Snack from drop down menu it shows it's value in next column automaticaly by fetching it from database plz help me urgentelyThis tells me that you have created a drop-down, hopefully from a database table. The table contains the products and prices. So, if you just add the prices into the drop-down as I explained, then you do NOT have to do a second database call to get the price again. Just add it to the drop-down and it is useable using PHP or Javascript and can be displayed in many ways. If you want the price to be displayed, just use Javascript, very easy to do. Since you did not ask exactly what you want, I guessed and gave you the solution to "automatically fetch the price". You mentioned column? Do you mean the column from a database row of data? Do you mean a column in a table? Either can pull the info from the drop-down. One way to do this is to add " onclick=getprice()" to the select and create a small Javascript routine to copy the drop-downs value to the area where you want to display it.
Perhaps you can rephrase your needs. I am sure we can help you out…
bro there is 1dropdown list whose data came from dbase when i click on some particular value i want it to show its price in next field which is also placed in same table
plz see the image
when i select some technician in the picture below i want that i show the salary that the selected technician is geting multiply by the total number entered in the billing hour text field
example
if i select employee 1 it shows its salary in billing rate box and multiiply it with the total # of working hours
and after that the form will be submited form further processing
Yes, this is very easy to do. You just assign the values of the tech’s to the select as we talked about before.
The rate is INSIDE the select attached to the tech’s name, “1” in your example…
Add the onclick clause to the select. (Drop-down) Then, the rate would be available for Javascript to load into your table’s rate field. Very easy to do…
I will walk you thru this step by step, but, first, you must tell me how you created the drop-down to start with.
My feeling is that you have a list of tech’s that are listed in a database table with their rates, names emails and
whatever else you wanted. Correct? So, in creating the actual drop-down, you pulled the names or ID nums
from the database. In that area you would also pull their rates and assign the “VALUE=” clause in the OPTION
to the value of the rate. So, the first one would be something like:
Now, when you create the SELECT tag for the drop-down, add " ONCLICK=“getrate()” at the end of it.
So, instead of
it would now be:
That change would set up the drop-down to to call a Javascript routine whenever the user changes techs.
And, then, create a function to copy the hidden rate in the drop-down to the table’s rate field. Let’s say the
table’s rate field is name tech_rate and looks like this:
So, the Javascript would look something like this:
All this JS script does is copy the value of the tech selected in the drop-down and place it in the field.
It’s quite simple. Now with that said… If you have a table of, let’s say five techs that you can select from
each having a drop-down, you would have to assign different names to each row so the JS script would know
where to store the data. That also is quite easy to do.
But, you can do it the hard way. To do that, you would have to use JQuery/Ajax and send a query out to
a PHP file that would be loaded into a hidden DIV and then call the same type of JS script to load the data
from the hidden DIV and move it to the field. Way too much work for this simple project.
So, Bro, I hope that now explains further what I was talking about. If not, you will have to show a ton more
code and explain further. Hope that helps you…
[php]<?php $eb = “SELECT EmployeeID,FirstName,LastName,BillingRate FROM employees”;
$res = mysql_query($eb);
$no_records = mysql_num_rows($res);
if($no_records > 0)
?>
<select name=‘select[]’ id=‘select[]’">
//no option Selected at first
<?php while($row =mysql_fetch_array($res)){
echo ‘<option value=’.$row[‘EmployeeID’].’>’.$row[‘LastName’],$row[‘FirstName’].’’;
}
?>[/php]
This is how i get the technicians from dbase i used EmployeeID as value because when the data is submited for further processing then at next step i again require the Selected Technician and if i assign salary as value then there may be many people taking same salary
thats why i dont use billingrate as value of employee.
bro i thing i have to use XML for this
so that when a tech is selected onchange function calls and i takes the tech id and give me its price
Okay, so, I see your code finally… LOL… Makes life simpler if it is all in front of you!
So, you can place anything you want into the VALUE. Here a further trick to store both the tech ID and
the rate in it…
Change this:
echo ‘<option value=’.$row[‘EmployeeID’].’>’.$row[‘LastName’],$row[‘FirstName’].’’;
To this:
echo ‘<option value=’.$row[‘EmployeeID’].’|’.$row[‘BillingRate’].’>’.$row[‘LastName’],$row[‘FirstName’].’’;
This will store two values in the drop-down. Like: “Ernie|25.50”
Then, in the JS routine, use this to separate them…
var tech_data = document.getElementById(‘techs’).value.split(’|’);
var tech_ID = tech_data[0];
var tech_rate = tech_data[1];
Then, use the previous code to store just the tech_rate… Hope that helps. Simple, easy, no second DB call.
I have to leave for a couple hours. If you can’t get it to work, post and I will check in when I get back…
thanks bro try your suggested code tomorrow as it’s very late and me now going to sleep
Thanks Bro Problem Solved
u helped me so much
Glad I could help… It is easier to do it this way than with XML. (In my opinion!)
See you in the next programming puzzle…