rich11 Posted October 23, 2007 Share Posted October 23, 2007 Hello, I was wondering how I set variable with two variables coming from a form and I would like to seperate them with a comma. I understand how to set a variable. $totaltext = "hello my friend!" ; I want to take these two variables from a form and put them together in one variable seperated by a comma echo $_POST["C1"]; echo $_POST["C2"]; $totaltext = echo $_POST["C1"] "," echo $_POST["C2"]; I know that is not the syntax, but I tried it and it didn;'t work. Thx, Rich Quote Link to comment Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 Hello, I was wondering how I set variable with two variables coming from a form and I would like to seperate them with a comma. I understand how to set a variable. $totaltext = "hello my friend!" ; I want to take these two variables from a form and put them together in one variable seperated by a comma echo $_POST["C1"]; echo $_POST["C2"]; $totaltext = echo $_POST["C1"] "," echo $_POST["C2"]; I know that is not the syntax, but I tried it and it didn;'t work. thanks, Rich $totaltext = $_POST["C1"].",".$_POST["C2"]; echo $totaltext; Quote Link to comment Share on other sites More sharing options...
rich11 Posted October 23, 2007 Author Share Posted October 23, 2007 Dude... THat was sweet!!!!!!!!! Worked like a charm. SO what is the significant of the period?? RIch Quote Link to comment Share on other sites More sharing options...
manixrock Posted October 23, 2007 Share Posted October 23, 2007 ok here's some tips: shortest way to get what you want is: $myvar = "$_POST[C1], $_POST[C2]"; you can do that because you can insert variables inside strings. Like: $n = 5; echo "n = $n"; // this would print "n = 5" now, with arrays it's the same, just that you MUST NOT put the <"> because it won't work $fullname = array("first" => "Bill", "second" => "Gates"); echo "My name is $fullname[first] $fullname[second]"; // prints "My name is Bill Gates" tips: when using strings you should be aware of the difference between <"> and <'>. The <"> is used for string that contain variables or escaped characters, like: "Today is $date. Have a nice day.\n". Notice the variable $date and the escaped character \n at the end, which is called the "new line character". If you use <'> then the variables and escaped characters are not inserted. This is faster that <"> and usefull if you use \ a lot. So you should generally use <'> unless you need to use variables inside in which case you should use <">. Quote Link to comment Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 Dude... THat was sweet!!!!!!!!! Worked like a charm. SO what is the significant of the period?? RIch It tells php where the variable ends Quote Link to comment Share on other sites More sharing options...
rich11 Posted October 23, 2007 Author Share Posted October 23, 2007 Ok.. I know that is getting off topic. But if I have 7 check boxes, and I only want them to answer two of them. Is there anyone way of doing that?? Rich Quote Link to comment Share on other sites More sharing options...
manixrock Posted October 23, 2007 Share Posted October 23, 2007 with the 7 checkboxes you should have a javascript code which prevents checking more boxes than 2, and then verify that only 2 checkboxes have been sent checked, otherwise preferably return an error message. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 $checkboxes = $_POST['checkboxes']; if(count($checkboxes) >= 2){ //allow }else { echo "you must select 2 or more to continue"; } <input type="checkbox" name="checkboxes[]" value="1"> <input type="checkbox" name="checkboxes[]" value="2"> <input type="checkbox" name="checkboxes[]" value="3"> <input type="checkbox" name="checkboxes[]" value="4"> Quote Link to comment Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 mgallforever hit the spot Quote Link to comment Share on other sites More sharing options...
rich11 Posted October 23, 2007 Author Share Posted October 23, 2007 Do you know of any good Javascript where i can get some code for that? Quote Link to comment Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 <SCRIPT LANGUAGE="JavaScript"> function anyCheck(form) { var total = 0; var max = form.checkboxes.length; for (var idx = 0; idx < max; idx++) { if (eval("document.form.checkboxes[" + idx + "].checked") == true) { total += 1; } } if(total >= 2) { return TRUE; }else { alert("Please select atleast two boxes")} } } </script> <form method="post" name="test" onSubmit="anyCheck(this.form)"> 1<input type=checkbox name="checkboxes[]"> <br>2<input type=checkbox name="checkboxes[]"> <br>3<input type=checkbox name="checkboxes[]"> <br>4<input type=checkbox name="checkboxes[]"> <br>5<input type=checkbox name="checkboxes[]"> <br>6<input type=checkbox name="checkboxes[]"> <br>7<input type=checkbox name="checkboxes[]"> <br>8<input type=checkbox name="checkboxes[]"> <br>9<input type=checkbox name="checkboxes[]"> <input type="submit"> </form> you could try that. http://javascript.internet.com/forms/checkbox-counter.html Quote Link to comment Share on other sites More sharing options...
rich11 Posted October 24, 2007 Author Share Posted October 24, 2007 For some reason.. it is not picking up the javascript. It just goes to the next page. Here is the code for the start of my form. Do you see any mistakes?? <form method="post" name="form" action="eerasinsert.php" onSubmit="anyCheck(this.form)"> Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.