Hide extra data in select field? - javascript

I am dynamically generating a select drop-down menu and was curious if there was a viable option to include additional information, perhaps a related database ID into the option value of the form. I am handling all the data flow using Javascript/Ajax and would like to know if this is possible in order to save database resources.

if no other way you can put db id as value . user will not see that.
<option value="CA+":"id+":"+something >California -- CA </option>
data manipulation depends on you - explode or split the value of option
anyway ..does not look good. !!!

Related

Make edits on dynamically loaded data using jQuery and PHP

I have a dropdown, on its change I need to load the contents related to it on the same page. Which I did using jQuery. Now the question is how do I make edits on this data and store it on my database. If I am wrong in using jQuery for loading my data then what else should I use? I am using PHP as my server side scripting language.
More detail -
Simply taking there a list of details I need to display as per the country you select, which I am displaying currently in a nice grid(textboxes)!
Now the data from this grid should be copied to another textbox on "EDIT" button click from where I edit them and store it in my database. I am not able to make the values copy into a another textbox
You could do this:
Display the data in some form of editable div, textarea, or other element.
Make a hidden field somewhere and when you display the data
Set the row id from your database to the hidden field
On your change event, grab the id from the hidden field along with the edited data.
Using Jquery/ajax, send that data to a php page that will save thee data to your database using the passed in id.
You could do that.
However, if it were me (and if you're not married to your current databse / mySQL etc..), I would use parse.com. The service is free up to a significant amount of usage (which Ive never come close to) and it really simplifies everything. See the below post if you're interested in that approach:
Save and retrieve user input from database with javascript?

How to display a link from the MySql database in html using jquery or php

I have cascading drop down form with 3 fields and 'Submit' button. Every field responds to each table in MySQL. So, if you choose an option from each drop down field and hit the 'Submit' button, the script returns and display an info of selected options. See an example: http://blueicestudios.com/chained-select-boxes/three-tier/
What I'm trying to do, is when every options are selected and the 'Submit' button is hit the link to the specific page should also displayed with an info of chosen option.
From an example: I selected a White Ford Mustang - For this type of selection I have a link to the page with a car in MySQL. But, I have no clue how to display it on the page. Any idea how to bring it to alive? Thanks
Just put the url in the form action:
$('form').attr('action','hondaCivicRed.php');
Or whatever they chose.
Submit will take them to the url
Edit:
$('document').on('change','#drop_3',function(){
var url = $('drop_1').val()+$('drop_2').val()+$('drop_3').val()+'.php';
$('form').attr('action',url);
});
It is actually quite a long answer to this question and too much code to write but here is the logic.
There are MUCH better ways of doing this (tables with JOINS etc.) but as a basic 'get it going' you just need to do the following (assuming you have worked out how to post the data and get the $_POST data back)
You could then set a table like so:
Manufacturer, Model, Colour, URL
Then just query the database with SELECT URL FROM table WHERE manufacturer=$_POST['manufactuer'] AND.....
(obviously the above is pseudo code but gives you the logic)
header('Location: $url); in your php.
Hope the above gives you an idea
The better way would be to dynamically create the pages from the database (so you dont need to create a new page for each colour, model etc.) but should give you a grounding

Sort and retrieve data with drop down menus in php

I have two drop down menus on my webpage. One is a course list and the other is a student list. What I want to do is, when a selection is made in the course menu it will update the student menu to only list students in that course.
All the course and student data is saved in a MySQL database. The SQL statements to retrieve the results I want are not a problem. I have those figured out. The problem is that I don't know how to get one drop down menu to update the other without the use of a submit button. Is there a way to have the course menu call a php function when it changes, and that will update the student menu?
I've looked through several similar questions, but a lot of them end up resetting the first menu when the second is updated. I need to print both the selected course and student on the page at the end.
Is this something that can be done with PHP, or would Javascript be more preferable? If someone could point em in the right direction, that would be much appreciated.
Is there a way to have the course menu call a php function when it changes, and that will update the student menu?
Yes. The buzz-word for this is AJAX.
You will end up using both JavaScript and PHP to do this. The actual implementation is quite involved, so I will list the basic steps for you.
(JavaScript) Bind the change event for the course drop down menu.
(JavaScript) When that event is fired, capture the selected course and fire an XMLHttpRequest off to your server along with the selected course.
(PHP) Capture the selected course, and run the SQL statement to fetch your students.
(PHP) Convert the student list to a text format (JSON, XML, delimited-text, etc.) to send back to the browser (using echo, print, etc).
(JavaScript) Populate the student drop down menu.
The general approach to this is to use jQuery to add a hook to your drop-down selector and trigger an AJAX load on another section of the page, populating that with data retrieved either as an HTML fragment (easy) or JSON data that's turned into one (harder).
A really quick and dirty version is to grab a portion of a page and re-populate the current document with it using $.load():
$('#select1').on('change', function() {
$('#select2').load('select.php #select2', 'select1=' + $(this).val())
})
That's the rough idea: When your first selection box changes, load the select.php page, or whatever you're using, and add on the parameter select=N where N is the selected value. It then rips out the #select2 section and replaces it.

Updating GridView without postback using javascript

I have a gridview and a dropdownlist on my page.
The gridview is binded through code behind with some columns. Among these price is also a column.
My scenario is to change the price field based on the dropdown criteria.
The price column consists of values in "lakhs", and i need to change them as crores or usd or some other format as per dropdown.
I don't want to go for postbacks. I want these to be implemented using javascript.
(These changes are for user conversion. They need not to be saved on database)
Thanks in advance
Madhu
You have two options. If you don't want to go for any response from the server (i.e. you don't want to make an AJAX call), you could populate a hidden field with a list of comma-delimited values that correspond to your dropdown values. It's an ugly approach, but it would work.
The other option is to make an AJAX call to a web method on the server (or possibly a financial service like Yahoo! Finance). When your dropdown selected value changes, that event fires a call to the server.
If you were able to indicate what platform you're using (PHP, .Net or other), someone will likely be able to provide more relevant examples and code samples.
Since the grid is rendered as an HTML Table, you can actually manipulate anything on the client.
I would pickup jQuery for the task

Country/State Dynamic Drop Down List

If you go to http://profile.microsoft.com and edit your personal information, you will select your country. When a country is selected the city and/or state information changes based on what is expected for that country. Does anyone have any examples on how to accomplish this? Is there any service (free service) that provides this information?
Because you tagged your question with "jquery", here is an example of a "Depending / Cascading Selectbox" (which you are searching)
Demo
Regarding the data: Country, State, Province WebService?
The CascadingDropdown control will give you this behavior.
You have to use Javascript to dynamically populate the city/state SELECT tag whenever the country SELECT tag is changed, which you can catch using an Event Handler.
Well it's based on your IP tracking, you can find users country via his IP address, all the list of Cities, for specific countries you can find somewhere and add it to your functionality, also you probably need some ajax functions for filing up drop downs or even better a JSON.

Categories

Resources