0

I am new in php, html5 and css. Hope you can help me with my problem.
I style it using css. Here are my codes:

<form method="post" name="testform" action="">

<a href="#modal"> <!-- when the input textbox was clicked, modal will pop up -->
    <input disabled type="text" name="test" placeholder="test" value="">
</a>

    <div class="modalwrapper" id="modal">   <!-- modal -->
            <div class="modalcontainer">    
                <div class="modalcol1">
                    <label>Test 1</label>
                    <input type="checkbox" name="test_modal[]" value="1">
                    <div class="clear"></div>
                    <label>Test 2</label>
                    <input type="checkbox" name="test_modal[]" value="2">
                    <div class="clear"></div>
                    <label>Test 3</label>
                    <input type="checkbox" name="test_modal[]" value="3">
                    <div class="clear"></div>
                    <label>Test 4</label>
                    <input type="checkbox" name="test_modal[]" value="4">
                    <div class="clear"></div>
                    <label>Test 5</label>
                    <input type="checkbox" name="test_modal[]" value="5">
                    <div class="clear"></div>

                    <div class="savebutton">
                        <input class="btn1" type="submit" value="Submit"/>
                    </div>
                </div>
            </div>
        <div class="overlay"></div>
    </div>      
</form>

Here is my css code for it.

/* modal layout */
    .modalwrapper {
        top: 0;
        left: 0;
        opacity: 0;
        position: absolute;
        visibility: hidden;
        box-shadow: 0 3px 7px rgba(0,0,0,.25);
        box-sizing: border-box;
        transition: all .4s ease-in-out;
        -webkit-transition: all .4s ease-in-out;
        -moz-transition: all .4s ease-in-out;
    }

    .modalwrapper:target {
        opacity: 1;
        visibility: visible
    }

    .overlay {
        background-color: #000;
        background: rgba(0,0,0,.8);
        height: 100%;
        left: 0;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1;
    }

    .modalcontainer {
        display: table;
        background-color: #777;
        position: relative;
        z-index: 100;
        color: #fff;
        padding: 5px;
    }

    .modalcol1 { display: table-cell; }

    .clear { clear: both; }

    .modalwrapper input[type=checkbox] {
        float: right;
        margin-right: 20px;
    }

    .savebutton input[type=submit] {
        float: right;
        background-color: maroon;
        color: #fff;
        border: none;
        padding: 5px 10px;
        margin-top: 5px;
        margin-right: 20px;
    }
    /* modal layout ends here */
  1. My problem is that when i clicked submit, it doesn't close the modal. I try redirecting it on the parent window but nothing happens, it doesn't close.

  2. I also have another question concerning how to count how many checkbox were checked using PHP. If 1 checkbox was checked, it will display the value of it and if more than 2 were checked it will echo a value "MORE"

Hope anyone can help me please. If my information are not enough, please let me know so i can update it. I want to learn more. Thanks in advance.

Let Soo Gas
  • 77
  • 1
  • 3
  • 12
  • Is that a bootstrap modal? Show us the js code too, please. PS: Why would you put a `input` inside `a`? – phaberest Dec 29 '16 at 15:04
  • @phaberest - i dont know how to use js totally. but i style and made a modal using css. i also put an input inside anchor tag because when the user clicked the input box which is disabled, the modal will pop-up. – Let Soo Gas Dec 29 '16 at 15:26

2 Answers2

0

To open and close your modal you have to use JS. I recommend you to use the jQuery library (Check out this article to learn how to use jQuery in your JS). With that, you can simply close the modal with .fadeOut():

$("#idofyourbutton").click(function(){ $("#idofyourmodal").fadeOut(); });

To count all your checked checkboxes, you can use i.e. this:

var l = $("input[type='checkbox']:checked").length;

After that, you can use if else to set the content of your input-field.

Andy
  • 393
  • 3
  • 16
  • hi. thanks for answering here. my post were updated. thank you so much – Let Soo Gas Dec 29 '16 at 15:48
  • I think I got your point now, look up my updated answer. Feedback me if that worked please. – Andy Dec 29 '16 at 16:09
  • Hi. I updated again my post. I dont know how to use bootstrap I just style it the way i style it and made a modal. Could you check my codes? I want it close after clicking the submit button and i wanna count how many were check. i just wanna close first the modal i made. Thank you so much and sorry for taking your time. – Let Soo Gas Dec 29 '16 at 16:16
  • No problem, this is what SO is here. Didn't know you aren't using Bootstrap. Check out my new answer using jQuery. Just ask if this doesn't help you. – Andy Dec 29 '16 at 16:25
  • @Mark Manalo Is my tip for your second question helpful? – Andy Dec 29 '16 at 17:57
  • hi, i posted another question somewhat related to this. hope you can help me with it? http://stackoverflow.com/questions/41393216/pass-the-value-of-check-checkbox-and-display-the-first-value-on-the-array – Let Soo Gas Dec 30 '16 at 09:54
  • I'll post an answer there, but for the next time, please do not open multiple questions on one task. Mark this as correct, so this question gets closed. – Andy Dec 30 '16 at 10:03
0

Make sure you actually follow the proper html format of Bootstrap modals. Pay attention to data and role attributes. Note how buttons that close modal have those attributes.

<div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>One fine body&hellip;</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

https://getbootstrap.com/javascript/#modals

Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
  • hi. my post were updated. i dont know boostrap. i was just used an id to call the modal and style it using css. thank you sir. – Let Soo Gas Dec 29 '16 at 15:47
  • You did only a portion of what I said. You did not pay attention to data attributes, ie data-dismiss="modal". Go through the html example one more time and copy attributes accordingly. – Serg Chernata Dec 29 '16 at 15:49
  • Hi. I updated again my post. I dont know how to use bootstrap I just style it the way i style it and made a modal. Could you check my codes? I want it close after clicking the submit button. Thank you so much and sorry for taking your time. – Let Soo Gas Dec 29 '16 at 16:14
  • Add data-dismiss="modal" to your submit button. As in: – Serg Chernata Dec 29 '16 at 16:16
  • hi. what library am i going to include on my head tag? – Let Soo Gas Dec 29 '16 at 16:24
  • Aren't you using bootstrap already? I don't understand your question. – Serg Chernata Dec 29 '16 at 16:25
  • hi mate. im not using bootstrap, my codes are posted but thank you so much. i solved it on my own on how to close that modal thing. i made a form for this: and made another form for the modal containing checkbox so that when i clicked its submit button it will go through on the above form and will close the modal. thank you so much for your time, maybe next time i will try to learn bootstrap. thank you so much for your help. now my problem is my question number 2 :) – Let Soo Gas Dec 29 '16 at 16:43
  • Hi mate. i posted another question somewhat related to this. Hope you can help me here please? – Let Soo Gas Dec 30 '16 at 09:52
  • http://stackoverflow.com/questions/41393216/pass-the-value-of-check-checkbox-and-display-the-first-value-on-the-array – Let Soo Gas Dec 30 '16 at 09:53