So, I'm pretty much a novice when it comes to programming and I would certainly appreciate a bit of help with an issue I'm having trouble getting my head around. Simply put, how do I get the selected variables from jquery.chained.remote.js back into my form for processing?
Here's the functioning, sort of, sample page.
http://www.noradaron.com/samplesearch/index.php
The dropdown list functions just fine but I just don't understand how to get the selected values back into my form. Yes, I will freely admit my knowledge is limited and I may not fully understand the answer once it is given. Regardless, I certainly appreciate any help I can get. Please let me know if there is anything else I could provide that would make my question more clear.
Attach submit event handler to your form like this:
$('form[name="search-vehicles"').submit(function() {
//code
});
Inside code grab the values like:
var value = $('#vType').val();
And update your text with the new values. However I recomment you to not write "textmore text" But to write your text inside *DIV*s or *SPAN*s with *ID*s so you can easily access them and change their values like:
<div id="selectedName"></div>
Then you can use:
$('#selectedName').html(value);
Beside putting id="vType" add name="vType" (and so on) so you can have your data sent back to server with either GET or POST .
Related
Right this has been asked before in similar context but the answer was not given.. I need to know how to change the contents of "homepage.php" (Example) PERMANENTLY by filling out a form on the webpage itself, I know I have to store data in MySQL database but how should I go about doing this (which way). I know how to store and retrieve data but just this particular problem has me baffled.
Do I save single css values into the database (e.g. blue, green, margin-left, margin-right) or can I store a whole css block of code as a variable then save it in the database
|| body { //Content of body } .navbar{ //navbar content here }? ||
End result I need is to edit a page without altering the code so that everyone can see it not just by using cookies. (Please do not tell me about needing a server ETC I know..)
I am using the Procedural method of PHP programming with no framework for those seeking to give an example.
Thanks in Advance =D!
I would post a comment but I don't have enough points to comment.
Would you be able to utilize jQuery for the webpage? I have had to do this exact same thing with php/mysql, and using jQuery .css() and .html() provides a working solution.
Okay. So I don't have any example code to show, but after doing a bit of research and learning the basics of PHP, I think the answer to my question should be pretty simple.
Here is the scenario, as I would like it to be:
On the homepage there will be several team names, with scores next to them. Like "house-points" in Harry Potter.
Below the score is a small text-field. Below that is a submit button.
The user will put a number in the text-field, press submit, and that number will be added to the team's total score.
NOW. I know how to achieve all of that with JavaScript. Easy. What I want to know IS:
How do I make that new number (the new score total) STAY there. I need to permanently alter the HTML when that submit button is pressed.
All I know is that I need to use PHP. I know the basics of PHP, so whatever the answer is, just throw it at me and I'll figure it out.
Sounds like what you want to do is submitting forms. First drop the JavaScript, you won't need it. What you need is to put your text fields in a form and when you submit you can fetch your values with $_<GET|POST|REQUEST>['<name_of_field>'].
Then you will need to store it somehow. The best way to do it is to use a database like MySQL or MongoDB to store it, but it could be a bit tricky if you are just learning this, so maybe you would like to stick to files. You could do this with INI files and PHP's INI functions.
Lastly you will need to print out the correct values to the website. Now this is easy: Just edit your HTML file to do something like
<?php echo $score['team1']; ?>
for each team after retrieving the correct values at the top or something. (Don't forget to rename the HTML file to .php as well).
Now you should be all set to save your scores. =)
If you mean really permanent you'll have to send it to a database via Ajax (combination of PHP and Javascript). OR write it to a text-document, which is less good.
Is there a php equivalent to something like this jquery:
var allInputs = $(":input"); allInputs.attr('type');
I need to retrieve the types from each of the post variables sent to a php script but I want to do it without using javascript and/or jquery, I guess it would also be nice to get the other attributes as well (id, class etc). Perhaps I have missed something but I have tried to find the answer to this on the internet in search engines etc and can't even find another question similar to this one!
Thanks for any help and advice.
There is no way to do this without passing the types from jquery or javascript. All php knows is that some strings are coming in.
You can do something like this:
$.post('blah.php',{
var1: 'test',
var1Type: 'text'
...
});
You're pretty confused, PHP is a server side language, any value in the $_POST array is just a value (precisely a string). PHP doesn't have any idea of the input type, it's just an HTTP request with some data in its body.
To be clearer, this is what your webserver sees when you're doing a post request:
Name=Jonathan+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21
PHP module reinterpret that input as key-values pairs, nothing more.
Everything is sent as a string. You have to know what are you using for and what types sent variables are and validate user input data.
So I've been struggling with finding a simple and efficient solution for the following problem. The solution I have now works, but since I'm working on this for the sake of learning ...
So, the case:
I have a PHP page which gets loads of persons from a DB, then sorts them and finally puts all persons
in a html list. What I'm after is a elegant solution to edit these persons by clicking on them from the list. I've found a jQuery pop-up solution that looks brilliant, but not so easy to use for beginners.
Since there are several persons I need to produce a different pop-up window depending
on which person is clicked. The problem is that the jQuery pop-up is based on the html being pre made, which is obviously hard since I don't know which person the user will click.
The best I've come up with so far is sending a GET -variable to the page with the person list, which then checks if there is a valid variable from GET and produces the HTML for the clicked person based on the id/variable. The problem with this is that I have to essentially run the same query twice; once to get all persons and once to get the clicked person. It isn't a big problem, it's more that since I'm new with jQuery I'm wondering if there is a simpler/better solution. I'm not really sure what jQuery can and can't do.
Thanks for any replies.
I'd start by asking why you don't ask the database to sort/ORDER the values before sending them back to your PHP page? It's well-suited for that sort of thing.
You could know which person was clicked if you added the database id to each element and passed that around. Have jQuery add it to the DOM element for each row in the HTML table.
kinda the standard way would be to pass the persons as JSON, and use the jquery templating system to build the forms. Of course this could be a bit daunting to a beginner, but its not that hard.
I have 2 checkboxes in a form and onclick of these, some php code needs to be executed and based on the result of the code, the checkbox is checked or unchecked.
So i have written onclick = document.formName.submit(); Now it is triggering the same page and i am able to write the code. I am not able to differentiate which checkbox is checked.
I don't want to use the procedure of:- calling javascript and then storing the value of the checkbox in a variable and making this variable as invisible.
I would like to write something like document.formName.submit('checkbox1'). So that i should be able to handle the value of this or i dont know.
Please suggest me an alternative method or better approach.
What exactly are you doing in the PHP code? Is it validating whether or not they are able to check that box? Sounds like you're making an extra unnecessary step here... If you could describe your scenario a little better I'm sure someone could point you to a more efficient way to accomplish this.
You can't do it correctly using either saving values in database or passing it as parameter.
you have to store somewhere so that when page is get refreshed it must come to know which checkbox is checked earlier.