Jump to content

Semsem

Members
  • Posts

    13
  • Joined

  • Last visited

Semsem's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Okay, so I have a bit of a problem. I have some code, the JS works (at least with the non-CSS modified version), but it fails with the CSS modified version. Wondering if anyone can lend me some help to figure out what went wrong with the implementation of the CSS... What I want to have happen, is the any of the first 4 chekboxes, if checked, disable all others. But, if any of the other checkboxes (numbers 5 and up) are checked, none are disabled (unless of course someone checks one of the first four). And all it's doing is disabling all when any checkbox is checked, not just the first four checkboxes are checked. My JavaScript: <script type="text/javascript"> $(window).load(function(){ var $inputs = $('input[type=checkbox]', $('#test')); var $inputs2 = $('input[type=checkbox]', $('#test2')); $inputs.change(function(){ var $this = $(this); $inputs.not(this).prop('disabled',($this.index() < 4 && this.checked)); if($this.index() < 4 && this.checked){ $inputs.not(this).prop('checked',false); } }); $inputs2.change(function(){ var $this = $(this); $inputs2.not(this).prop('disabled',($this.index() < 4 && this.checked)); if($this.index() < 4 && this.checked){ $inputs2.not(this).prop('checked',false); } }); }); The first Div: <div id="test" style="float:left; width:50%"> <table border="0" cellpadding="0" cellspacing="0"> <tr><td style="font-size:3px"> </td></tr> <tr> <p id="Error" style="background: #ff0000; color: #fff;">Please, enter data</p></tr> <td width="150px"><input type="checkbox" id="f1" name="1" class="css-checkbox" value="1" /> <label for="f1" class="css-label">1</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f2" name="2" class="css-checkbox" value="2" /> <label for="f2" class="css-label">2</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f3" name="3" class="css-checkbox" value="3" /> <label for="f3" class="css-label">3</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f4" name="4" class="css-checkbox" value="4" /> <label for="f4" class="css-label">4</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f5" name="5" class="css-checkbox" value="5" /> <label for="f5" class="css-label">5</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f6" name="6" class="css-checkbox" value="6" /> <label for="f6" class="css-label">6</label></td></tr> </table> </div> My CSS, if needed: <style> #Error {display: none;} input[type=checkbox].css-checkbox {display:none;} input[type=checkbox].css-checkbox + label.css-label {padding-left:20px;height:20px;display:inline-block;line-height:20px;background-repeat:no-repeat;background-position: 0 0;font-size:15px;vertical-align:middle;cursor:pointer;} input[type=checkbox].css-checkbox:checked + label.css-label {background-position: 0 -20px;} input[type=checkbox].css-checkbox:disabled + label.css-label {background-position: 0 -40px;} .css-label{ background-image:url(web-two-style.png);} </style> The problem is: the following works, and the following was later modified with CSS and I can't figure out what went wrong. What works: <div id='test'> <input type="checkbox" name="check1" value="1" id="check1" >first <input type="checkbox" name="check2" value="1" id="check2" >second <input type="checkbox" name="check3" value="1" id="check3" >third <input type="checkbox" name="check4" value="1" id="check4" >fourth <input type="checkbox" name="check5" value="1" id="check5" >fifth <input type="checkbox" name="check6" value="1" id="check6" >sixth <input type="checkbox" name="check7" value="1" id="check7" >seventh <input type="checkbox" name="check8" value="1" id="check8" >eight </div> It gets even odder when I add the code that worked to the same div as the one that doesn't, since it the above non-CSS then works properly and will disable (where appropriate) all the checkboxes regardless of CSS, but when the CSS are checked, all are disabled: <div id="test" style="float:left; width:50%"> <table border="0" cellpadding="0" cellspacing="0"> <tr><td style="font-size:3px"> </td></tr> <tr> <p id="Error" style="background: #ff0000; color: #fff;">Please, enter data</p></tr> <td width="150px"><input type="checkbox" id="f1" name="1" class="css-checkbox" value="1" /> <label for="f1" class="css-label">1</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f2" name="2" class="css-checkbox" value="2" /> <label for="f2" class="css-label">2</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f3" name="3" class="css-checkbox" value="3" /> <label for="f3" class="css-label">3</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f4" name="4" class="css-checkbox" value="4" /> <label for="f4" class="css-label">4</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f5" name="5" class="css-checkbox" value="5" /> <label for="f5" class="css-label">5</label></td></tr><tr> <td width="150px"><input type="checkbox" id="f6" name="6" class="css-checkbox" value="6" /> <label for="f6" class="css-label">6</label></td></tr> <input type="checkbox" name="check1" value="1" id="check1" >first <input type="checkbox" name="check2" value="1" id="check2" >second <input type="checkbox" name="check3" value="1" id="check3" >third <input type="checkbox" name="check4" value="1" id="check4" >fourth <input type="checkbox" name="check5" value="1" id="check5" >fifth <input type="checkbox" name="check6" value="1" id="check6" >sixth <input type="checkbox" name="check7" value="1" id="check7" >seventh <input type="checkbox" name="check8" value="1" id="check8" >eight </table> </div> Using the latest jQuery version, if needed.
  2. Both work. Thank you for your assistance. However, the second one needs to be written as: $required = array("A" => "Field A", "B" => "Field B", "C" => "Field C"); $missing = array(); foreach ($required as $name => $label) { if (empty($_POST[$name])) { $items[] = $label; } } With $items[], so that it works properly with the format_list function from the above. Otherwise it worked just fine. Thanks again.
  3. I don't think that's exactly what I meant. Let me try to explain it a bit more: I have a form, and I want the user to be able to input data into it, and upon submit, have it echo somewhere (not quite sure where I want it echoed yet) which input fields the user did not enter data, and have it be echoed as something meaningful rather than the name of the input tag. The way my code originally was written (below) would allow me to echo the names of the input tags, and if one of them contained user inputted data, it would skip echoing that one and echo the ones that didn't contain user inputted data. function format_list( $items ) { if ( count( $items ) == 0 ) return ''; if ( count( $items ) == 1 ) return $items[0]; $last_item = array_pop( $items ); $list_text = join( ', ', $items ) . ' and ' . $last_item; return $list_text; } $items = array(); $keys = array( 'A', 'B', 'C' ); foreach ( $keys as $key ) { if ( empty( $_POST[$key] ) ) $items[] = $key; } So, what I want to be able to do is create an alias, per se, of the input names, so that if input name=A is left blank, it would echo somewhere as some other name than "A".
  4. Both of those examples do the same thing, I prefer the second one to be honest, it's simpler! It does echo ValueA, ValueB, and ValueC, but the way I had it before, if none of the input fields had any text entered in them, it'd echo "A, B and C" but if the input field for A, for instance, had something typed into it, upon submit, once the function was called, it'd echo "B and C". Your edit, however, echo's "ValueA, ValueB and ValueC", but when something is typed into the input field for A (let's say "Value for Input A", it then echo's "Value in Input A, ValueB and ValueC" instead of "ValueB and ValueC" like I'd want it to. I've tried editing your code, and none of the following work: $items = array("customName" => "ValueA", "B" => "ValueB", "C" => "ValueC"); foreach (array_keys($items) as $key) { if (!empty($_POST[$key])) { $items[] = $key; } } It echo's "ValueA, ValueB, ValueC and A" And: $items = array("customName" => "ValueA", "B" => "ValueB", "C" => "ValueC"); foreach (array_keys($items) as $key) { if (!empty($_POST[$key])) { $items[$key] = $key; } } It echo's "A, ValueB and ValueC" Any ideas? If you understand what I'm looking to do?
  5. So, what I'm trying to do is rather simple. I have some input fields, and upon POST, I want to tell whether the user has entered values or not, and if not, to echo the values later on in code. The code that works: function format_list( $items ) { if ( count( $items ) == 0 ) return ''; if ( count( $items ) == 1 ) return $items[0]; $last_item = array_pop( $items ); $list_text = join( ', ', $items ) . ' and ' . $last_item; return $list_text; } $items = array(); $keys = array( 'A', 'B', 'C' ); foreach ( $keys as $key ) { if ( empty( $_POST[$key] ) ) $items[] = $key; } echo format_list( $items ); But, what I want to do is instead of echoing "A" or "B" or "C", I want it to echo something more meaningful, something the user later in the code, or me later down the road, can understand better. So, I have tried to basically alias the array, and am trying to get the values in the alias to be the values assigned in $items My code that doesn't exactly work: function format_list( $items ) { if ( count( $items ) == 0 ) return ''; if ( count( $items ) == 1 ) return $items[0]; $last_item = array_pop( $items ); $list_text = join( ', ', $items ) . ' and ' . $last_item; return $list_text; } $items = array(); $keys = array( 'A', 'B', 'C' ); $keys2 = array( 'ValueA', 'ValueB', 'ValueC' ); $keys3 = array_combine($keys, $keys2); foreach ( $keys3 as $key ) { if ( empty( $_POST[array_keys($key)] ) ) $items[] = array_values($key); } echo format_list( $items ); I know the Values aren't really any clearer to anyone, I'll have to edit it later, I just want to get it working first. What that does is tell me: Warning: array_keys() expects parameter 1 to be array, string given in X.php on line 53 Warning: array_values() expects parameter 1 to be array, string given in X.php on line 54 Warning: array_keys() expects parameter 1 to be array, string given in X.php on line 53 Warning: array_values() expects parameter 1 to be array, string given in X.php on line 54 Warning: array_keys() expects parameter 1 to be array, string given in X.php on line 53 Warning: array_values() expects parameter 1 to be array, string given in X.php on line 54 And echo's ", and" I cannot see what I'm doing wrong. I create a new array, combine it with the first (to "alias" is), and then want to split it apart...and then it fails to work. Any help would be appreciated.
  6. Line 15: Line 16: microtime_float(); Line 17: Line 18: $time = date(F." ".d.", ".Y." ".g.":".i.":".sa,time()); Line 19: Line 20: $schedule = mysql_query("SELECT * FROM `downTime` WHERE `isActive`='1'"); Lines 15, 17, and 19 are blank lines.
  7. Notice: Use of undefined constant F - assumed 'F' in /home/..../public_html/...../X.php on line 18 Notice: Use of undefined constant d - assumed 'd' in /home/..../public_html/...../X.php on line 18 Notice: Use of undefined constant Y - assumed 'Y' in /home/..../public_html/...../X.php on line 18 Notice: Use of undefined constant g - assumed 'g' in /home/..../public_html/...../X.php on line 18 Notice: Use of undefined constant i - assumed 'i' in /home/..../public_html/...../X.php on line 18 Notice: Use of undefined constant sa - assumed 'sa' in /home/..../public_html/...../X.php on line 18 Notice: Undefined variable: scheduled in /home/..../public_html/...../X.php on line 24 Notice: Undefined index: page in /home/..../public_html/...../X.php on line 58 Notice: Undefined index: page in /home/..../public_html/...../X.php on line 68 Notice: Undefined index: page in /home/..../public_html/...../X.php on line 79 Line 18: $time = date(F." ".d.", ".Y." ".g.":".i.":".sa,time()); Line 24: $scheduled .= "<span style='color:#FF0000'>F</span>";} Line 58: <? if($_GET['page'] != "startTime"){ ?> Line 68: <? if($_GET['page'] == "ajax"){?> Line 79: if($_GET['page'] == "startTime"){?> Nothing of this, as far as I can tell, deals with the JS. However, I'm not sure why any of those lines are throwing (secret) errors.
  8. That doesn't work either. I'm approaching day 4 working on solving this, getting a little frustrated. When I tried this, it didn't work at all: if($_GET['page'] == "startTime"){ if(isset($_POST['newTime'])){ echo '<script>window.location = "anyPage.php"</script>';}?> Don't know why. Even if I move the isset to the top of the page, before the if($_GET, it still doesn't work. The last time ANYTHING worked properly, it was: <? if($_GET['page'] == "startTime"){?> <script> function closeFB() { <? $unix = mktime(0, 0, 0, 1, 1, $_POST['year']); ?> $("#startTimeDiv").html("<div id='message'></div>"); $("#message").html("<p>X</p>") .append("<p>X<br><? echo $unix; ?></p>"); $.fancybox.close(); } </script> With the submit button as follows: <tr> <td colspan="2" align="center"><br /><input class="czas" type="submit" onClick="closeFB();" name="newTime" value="Set Start Time" /></td></tr> </form> </table> </div> <? die(); } ?> And when that ran, it returns a unix timstamp of 946702800, where if I change it to mktime(0, 0, 0, 1, 1, 2015);, it returns 1420092000, which is proper. But, with the former, when I view the source code on the page (before I hit any buttons), and click the link in the source code (via FF) to the anyPage.php?page=startTime, I see: <script> function closeFB() { $("#startTimeDiv").html("<div id='message'></div>"); $("#message").html("<p>Contact Form Submitted!</p>") .append("<p>We will be in touch soon.<br>946702800</p>"); $.fancybox.close(); } </script> The JS ran before the input field had a chance to be inputted and before the button could have been pressed. I know I could make the input field into a JS variable, but that puts me back to square one with how to then pass the JS variable to the PHP mktime function, since it would have to be done before the JS ran. And as stated above, your input, which probably will help eventually, did not solve my problem...but it may be a start to solving my problem.
  9. Okay, so my code is (currently) as follows: <? if($_GET['page'] == "startTime"){ if(isset($_POST['newTime'])){ $unix = mktime(0, 0, 0, 1, 1, $_POST['year']); echo ('<script> function closeFB() { $("#startTimeDiv").html("<div id="message"></div>"); $("#message").html("<p>X</p>") .append("<p>X<br><? echo $unix; ?></p>"); $.fancybox.close(); } </script>'); echo '<script type="text/javascript">' , 'closeFB();' , '</script>'; } ?> Then there's a whole big table which ends with: <td colspan="2" align="center"><br /><input class="czas" type="submit" name="newTime" value="Set Start Time" /></td></tr> </form> </table> </div> <? die(); } ?> Okay, so what I want is the user to be able to put in a custom time (in the above code, only the year is currently customizable, that will be expanded when I figure out how to get the year to work). The user inputs the year, which in the form corresponds with the PHP $_POST['year']. So, what I want is for the use to input the year, and when on submit, $_POST['year'] to then contain a number, to then include the mktime function, to then echo the javascript function which also has a php echo of the mktime output, and then to call the javascript function. Every time I include the JS function inside the webpage, instead of what I'm trying to do here and echo it (load it) at the proper time, it pre-runs through mktime and since mktime does not contain a year value until submit, it doesn't work properly. But, when I do it like I've done it and echo JS after the submit button is clicked, the JS function apparently is not working. Any ideas? Struggling with server-side vs client-side to know what I'm doing right/wrong...
  10. Alright, I think this is mostly a JavaScript issue now. When <? $unix = mktime(0, 0, 0, 1, 1, 2015);?>, and I look at the page's source from the browser, I am able to see the unix timestamp in the function. When it it <? $unix = mktime(0, 0, 0, 1, 1, $_POST["year"]);?> there is no number in the page's source. So it appears as though my problem is that the code is running before it should (before any variables are entered). Any ideas on how to fix it?
  11. Okay, it was working properly (the PHP code, anyway), I took it to a new page and it worked. So it means that the error is not necessarily the PHP like I had thought but something to do with JavaScript (which I also hate). HTML submit is as follows: <input class="czas" type="submit" onClick="closeFB();" name="newTime" value="Set Time" /> Currently, my function is as follows: <script> function closeFB() { <? $unix = mktime(0, 0, 0, 1, 1, $_POST["year"]);?> $("#startTimeDiv").html("<div id='message'></div>"); $('#message').html("<p>X</p>") .append("<p>X<br><? echo $unix; ?></p>") $.fancybox.close(); } </script> I'm also using Fancybox to open up the time form in a modal popup, have user enter the time, hit to Set the Time, have the modal popup close and update a couple divs with new info. It works fine when using <? $unix = mktime(0, 0, 0, 1, 1, 2015);?>, but the second I change 2015 to $_POST["year"], it then fails. The problem why var_dump and print_r would not work was due to JavaScript not being able to can't split a string across lines (it returned the error of unterminated string literal in FireBug), which is why I moved the code to a new page and isolated it, where it worked. But, I think this is a JavaScript problem, and I think it has to additionally be a PHP problem. Any help would be appreciated.
  12. Yes, they are number fields. When I do something like, $unix = mktime(0, 0, 0, 1, 1, 2015); it returns the value of 1420088400, which is proper, Jan 1, 2015 00:00:00, but when I do $unix = mktime(0, 0, 0, 1, 1, $_POST["year"]); it produces 943938000, which is Nov 30, 1999. The form does not work at all when I put var_dump($_POST); or var_dump(unix); or var_dump($_POST["year"]); To be honest, that's the first time I've ever heard of var_dump, which is very sad.
  13. Okay, let's get this straight off the bat: I hate manipulating time in PHP. I don't understand any but a little bit of it. Okay, so my problem is rather simple, I think. I have a form, where the use inputs the date variables. I then want to combine those individual variables into a date, and then export the date in UNIX time. $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $hour = $_POST['hour']; $min = $_POST['min']; $sec = $_POST['sec']; $date = new DateTime(); $date->setDate($year, $month, $day); $date->setTime($hour, $min, $sec); Then, to export UNIX: $date->format("U"); Problem is, when all those variables instead of having a "$_POST" variable attached, but have a default manually inserted number, ie, $year = 2013; (and continued like that), it works just fine and I am able to get a UNIX time stamp for whatever date I manually code into the PHP. But, what I want to be able to do is have the user enter the various time variables from a form (without the variables being hard coded in), and have it do the same. If anyone understands what I am wanting to do, any assitance in this matter would be greatly appreciated. I've tried (unsuccessfully) using strtotime and mktime and DateTime and combinations of the three, to no avail. And, after around 4 hours experimenting and Googling, I have to admit I need help as I am getting nowhere. Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.