I want to do the following but I want to find out if its possible and whats the easiest way to do it before I spend hours looking on google for something that isn't possible. The situation is a web app that would run of a users localhost so they can configure a config.php file.
Can the number of available check boxes be set in a config.php file. ie.
$numberofcheckboxes ="4"
Can descriptions be set for these in the config.php ie.
When these check boxes are displayed and ticked and then submitted can a php function be run with variables depending on which checkboxes were ticked. So in the config.php you would set the different variables for each checkbox. ie.
$check1name = "name 1"
$check1size ="120"
$check2name ="name 2"
$check2size ="160"
The function is always exactly the same function however the variables will be different for each checkbox.
Is this possible?
Thanks
I'm not quite sure I understand your final aim, but the ideas you describe sound feasible to me. However, I'd recommend defining the checkboxes and their details using an associative array, instead of as individual variables. Then you can use count($checkbox_array) to see how many checkboxes there are, and reference certain values using the number of the checkbox, like $checkbox_array[0]['name'].
Also, be aware of the difference between strings and integers. $numberofcheckboxes="4"; assigns a string, whereas $numberofcheckboxes=4; assigns an integer. Because PHP is loosely-typed you might not notice the difference in this case, but it is nonetheless an important difference to understand.
I think, you can use jquery...
Give your checkbox the same class, something like "chkclass". And give the value of checkbox in the value property. Then you can make a function that runs every click. Look at this code.
$(".chkclass").click(function(){
if($(this).is(":checked")){
//add your code here
//if you want to call some php with ajax, you can use .load function from jquery
}
});
I wish this is what you're talking about.. :)
Related
I know the question seems kind of misleading or confusing, but here's what I mean.
If you have a link in HTML, I read that you can do something like this:
<a href="index.html?hi=0">
The above link is supposed to take you to the same page, but with a new value of hi that is equal to 0. First off, is it true that you can do that? You could also change the value of hi through different links by using the same code as above.
Here's the sort of second part to my question. How can you retrieve that value in php? I saw that you could, but I forgot how. For example, what if the link to the page was index.html?hi=2. How could you retrieve the value of hi in php? Anyways, I hope you can solve my problem and understand it. Thanks in advance!
Everything after the ? in a URL is called the Query String, and yes you can call the same page with different data there.
PHP will automatically parse the Query String and place it's values in the superglobal $_GET for your convenience, so for instance in index.php?hi=1 you can read $_GET['hi'] to get the value of "hi".
Multiple variables can be passed this way, like index.php?foo=1&bar=2 will deliver $_GET['foo'] with value 1 and $_GET['bar'] with value 2.
You can simply use & to separate variables in most cases, but to ensure correct formating, use http_build_query() to convert an associative array into a valid Query String.
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.
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 .
I've been looking all over for a sample script, but I haven't been able to find one. Basically, I want to have the code get a value from a div and multiply that number based on the user input. For example, if I have a site for recipes, and I want to have a calculator where the user enters the amount of servings that they need, and it'll change the recipe to give the amount of servings specified. (you can see an example HERE.)
you have to use $_POST or $_GET
To get the users input.
Then you can manipulate it according to your needs and then display it back to the users using echo
i think you can solve the problem with Javascript too !
if you are using PHP then do like this
if (isset($_POST['num1'],$_POST['num2'],$_POST['operator']))
{
...
}
if you do not use ISSET it will show warnings that $_POST is undefined or so...
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.