Updating display from php if statement live












0















I've set up my input as listed below, which the question to fill in input for if is only prompted on either $client_chargeBy is either == "Square Foot" or "Room"



 <div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
<div class=" form-group "><label for="enjoy_style" class="optional">How are your rates charged by?</label>
<select name="client_chargeBy" id="client_chargeBy" value="{{$client_chargeBy}}" class="form-control ">
<option value="Square Foot">Square Foot</option>
<option value="Room">Room</option>
<option value="View">View</option>
<option value="Hour">Hour</option>
</select>
</div>
</div>
<div class="col-md-6 PR0 p0_smresp">
<div class=" form-group "><label for="client_chargeRate" class="optional">What is your rates?</label>
<input type="text" name="client_chargeRate" id="client_chargeRate" value="{{$client_chargeRate}}" class="form-control" autocomplete="off" placeholder="List your charge rate" aria-required="true">
</div>
</div>
</div>
<div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
@if($client_chargeBy == "Room")
input days for Room
@elseif($client_chargeBy == "Square Foot")
input days for SF
@endif
</div>
</div>


However the approach I used will only display the input when I've submitted the form first. I want to make it such that "input days for Room" or "input days for SF" prompt will display right after i change the select option without having to save it first.










share|improve this question


















  • 1





    As PHP runs serverside you have to do that with javascript or jquery.

    – ratmalwer
    Nov 22 '18 at 17:40
















0















I've set up my input as listed below, which the question to fill in input for if is only prompted on either $client_chargeBy is either == "Square Foot" or "Room"



 <div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
<div class=" form-group "><label for="enjoy_style" class="optional">How are your rates charged by?</label>
<select name="client_chargeBy" id="client_chargeBy" value="{{$client_chargeBy}}" class="form-control ">
<option value="Square Foot">Square Foot</option>
<option value="Room">Room</option>
<option value="View">View</option>
<option value="Hour">Hour</option>
</select>
</div>
</div>
<div class="col-md-6 PR0 p0_smresp">
<div class=" form-group "><label for="client_chargeRate" class="optional">What is your rates?</label>
<input type="text" name="client_chargeRate" id="client_chargeRate" value="{{$client_chargeRate}}" class="form-control" autocomplete="off" placeholder="List your charge rate" aria-required="true">
</div>
</div>
</div>
<div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
@if($client_chargeBy == "Room")
input days for Room
@elseif($client_chargeBy == "Square Foot")
input days for SF
@endif
</div>
</div>


However the approach I used will only display the input when I've submitted the form first. I want to make it such that "input days for Room" or "input days for SF" prompt will display right after i change the select option without having to save it first.










share|improve this question


















  • 1





    As PHP runs serverside you have to do that with javascript or jquery.

    – ratmalwer
    Nov 22 '18 at 17:40














0












0








0








I've set up my input as listed below, which the question to fill in input for if is only prompted on either $client_chargeBy is either == "Square Foot" or "Room"



 <div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
<div class=" form-group "><label for="enjoy_style" class="optional">How are your rates charged by?</label>
<select name="client_chargeBy" id="client_chargeBy" value="{{$client_chargeBy}}" class="form-control ">
<option value="Square Foot">Square Foot</option>
<option value="Room">Room</option>
<option value="View">View</option>
<option value="Hour">Hour</option>
</select>
</div>
</div>
<div class="col-md-6 PR0 p0_smresp">
<div class=" form-group "><label for="client_chargeRate" class="optional">What is your rates?</label>
<input type="text" name="client_chargeRate" id="client_chargeRate" value="{{$client_chargeRate}}" class="form-control" autocomplete="off" placeholder="List your charge rate" aria-required="true">
</div>
</div>
</div>
<div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
@if($client_chargeBy == "Room")
input days for Room
@elseif($client_chargeBy == "Square Foot")
input days for SF
@endif
</div>
</div>


However the approach I used will only display the input when I've submitted the form first. I want to make it such that "input days for Room" or "input days for SF" prompt will display right after i change the select option without having to save it first.










share|improve this question














I've set up my input as listed below, which the question to fill in input for if is only prompted on either $client_chargeBy is either == "Square Foot" or "Room"



 <div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
<div class=" form-group "><label for="enjoy_style" class="optional">How are your rates charged by?</label>
<select name="client_chargeBy" id="client_chargeBy" value="{{$client_chargeBy}}" class="form-control ">
<option value="Square Foot">Square Foot</option>
<option value="Room">Room</option>
<option value="View">View</option>
<option value="Hour">Hour</option>
</select>
</div>
</div>
<div class="col-md-6 PR0 p0_smresp">
<div class=" form-group "><label for="client_chargeRate" class="optional">What is your rates?</label>
<input type="text" name="client_chargeRate" id="client_chargeRate" value="{{$client_chargeRate}}" class="form-control" autocomplete="off" placeholder="List your charge rate" aria-required="true">
</div>
</div>
</div>
<div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
@if($client_chargeBy == "Room")
input days for Room
@elseif($client_chargeBy == "Square Foot")
input days for SF
@endif
</div>
</div>


However the approach I used will only display the input when I've submitted the form first. I want to make it such that "input days for Room" or "input days for SF" prompt will display right after i change the select option without having to save it first.







php html laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 17:24









MonomoniMonomoni

5319




5319








  • 1





    As PHP runs serverside you have to do that with javascript or jquery.

    – ratmalwer
    Nov 22 '18 at 17:40














  • 1





    As PHP runs serverside you have to do that with javascript or jquery.

    – ratmalwer
    Nov 22 '18 at 17:40








1




1





As PHP runs serverside you have to do that with javascript or jquery.

– ratmalwer
Nov 22 '18 at 17:40





As PHP runs serverside you have to do that with javascript or jquery.

– ratmalwer
Nov 22 '18 at 17:40












2 Answers
2






active

oldest

votes


















0














In order to handle this live on document change, you can do it via Javascript since PHP is only used for server side rendering where variables are set prior to the HTML document render. I suggest changing your HTML document a little to cater to easy Javascript element handling;



 <div class="col-md-12 p0 ">
<div class="col-md-6 PL0 p0_smresp">
input days for <span id="textToChange">SF</span>
</div>
</div>


And your Javascript would be






var selectElement = document.getElementById('client_chargeBy');
selectElement.addEventListener('change', function() {
let selectedIndex = selectElement.selectedIndex;
var optionValue = selectElement[selectedIndex].value;
var spanText = document.getElementById('textToChange');
var updateValue = 'SF';
switch(optionValue) {
case 'Room':
updateValue = 'Room';
break;
case 'Square Foot':
updateValue = "SF";
break;
}
spanText.innerHTML = updateValue;
});





Also, I would recommend you to read up more on the concept on live update on a webpage as @Banujan suggested. It will be very useful in the long run as a developer.






share|improve this answer































    0














    First of all PHP is a server site script. It runs on the server then return the results. Thats all. There is nothing else between your browser and server after get the response.



    Every time when you run a .PHP the page will be loading and waiting for server's response. You can't do anything on page before site loaded. So if you want get real time update from server (Without refresh/reload site) You should make a background connection (Web-Socket) Or you should ask server for any updates frequently in background (AJAX)



    So here you should make a background connection to server using Javascript. Its a client side, It will connect client and server.



    This is a very basic concept.. Refer this links to learn



    Ajax request Websoket






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435805%2fupdating-display-from-php-if-statement-live%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      In order to handle this live on document change, you can do it via Javascript since PHP is only used for server side rendering where variables are set prior to the HTML document render. I suggest changing your HTML document a little to cater to easy Javascript element handling;



       <div class="col-md-12 p0 ">
      <div class="col-md-6 PL0 p0_smresp">
      input days for <span id="textToChange">SF</span>
      </div>
      </div>


      And your Javascript would be






      var selectElement = document.getElementById('client_chargeBy');
      selectElement.addEventListener('change', function() {
      let selectedIndex = selectElement.selectedIndex;
      var optionValue = selectElement[selectedIndex].value;
      var spanText = document.getElementById('textToChange');
      var updateValue = 'SF';
      switch(optionValue) {
      case 'Room':
      updateValue = 'Room';
      break;
      case 'Square Foot':
      updateValue = "SF";
      break;
      }
      spanText.innerHTML = updateValue;
      });





      Also, I would recommend you to read up more on the concept on live update on a webpage as @Banujan suggested. It will be very useful in the long run as a developer.






      share|improve this answer




























        0














        In order to handle this live on document change, you can do it via Javascript since PHP is only used for server side rendering where variables are set prior to the HTML document render. I suggest changing your HTML document a little to cater to easy Javascript element handling;



         <div class="col-md-12 p0 ">
        <div class="col-md-6 PL0 p0_smresp">
        input days for <span id="textToChange">SF</span>
        </div>
        </div>


        And your Javascript would be






        var selectElement = document.getElementById('client_chargeBy');
        selectElement.addEventListener('change', function() {
        let selectedIndex = selectElement.selectedIndex;
        var optionValue = selectElement[selectedIndex].value;
        var spanText = document.getElementById('textToChange');
        var updateValue = 'SF';
        switch(optionValue) {
        case 'Room':
        updateValue = 'Room';
        break;
        case 'Square Foot':
        updateValue = "SF";
        break;
        }
        spanText.innerHTML = updateValue;
        });





        Also, I would recommend you to read up more on the concept on live update on a webpage as @Banujan suggested. It will be very useful in the long run as a developer.






        share|improve this answer


























          0












          0








          0







          In order to handle this live on document change, you can do it via Javascript since PHP is only used for server side rendering where variables are set prior to the HTML document render. I suggest changing your HTML document a little to cater to easy Javascript element handling;



           <div class="col-md-12 p0 ">
          <div class="col-md-6 PL0 p0_smresp">
          input days for <span id="textToChange">SF</span>
          </div>
          </div>


          And your Javascript would be






          var selectElement = document.getElementById('client_chargeBy');
          selectElement.addEventListener('change', function() {
          let selectedIndex = selectElement.selectedIndex;
          var optionValue = selectElement[selectedIndex].value;
          var spanText = document.getElementById('textToChange');
          var updateValue = 'SF';
          switch(optionValue) {
          case 'Room':
          updateValue = 'Room';
          break;
          case 'Square Foot':
          updateValue = "SF";
          break;
          }
          spanText.innerHTML = updateValue;
          });





          Also, I would recommend you to read up more on the concept on live update on a webpage as @Banujan suggested. It will be very useful in the long run as a developer.






          share|improve this answer













          In order to handle this live on document change, you can do it via Javascript since PHP is only used for server side rendering where variables are set prior to the HTML document render. I suggest changing your HTML document a little to cater to easy Javascript element handling;



           <div class="col-md-12 p0 ">
          <div class="col-md-6 PL0 p0_smresp">
          input days for <span id="textToChange">SF</span>
          </div>
          </div>


          And your Javascript would be






          var selectElement = document.getElementById('client_chargeBy');
          selectElement.addEventListener('change', function() {
          let selectedIndex = selectElement.selectedIndex;
          var optionValue = selectElement[selectedIndex].value;
          var spanText = document.getElementById('textToChange');
          var updateValue = 'SF';
          switch(optionValue) {
          case 'Room':
          updateValue = 'Room';
          break;
          case 'Square Foot':
          updateValue = "SF";
          break;
          }
          spanText.innerHTML = updateValue;
          });





          Also, I would recommend you to read up more on the concept on live update on a webpage as @Banujan suggested. It will be very useful in the long run as a developer.






          var selectElement = document.getElementById('client_chargeBy');
          selectElement.addEventListener('change', function() {
          let selectedIndex = selectElement.selectedIndex;
          var optionValue = selectElement[selectedIndex].value;
          var spanText = document.getElementById('textToChange');
          var updateValue = 'SF';
          switch(optionValue) {
          case 'Room':
          updateValue = 'Room';
          break;
          case 'Square Foot':
          updateValue = "SF";
          break;
          }
          spanText.innerHTML = updateValue;
          });





          var selectElement = document.getElementById('client_chargeBy');
          selectElement.addEventListener('change', function() {
          let selectedIndex = selectElement.selectedIndex;
          var optionValue = selectElement[selectedIndex].value;
          var spanText = document.getElementById('textToChange');
          var updateValue = 'SF';
          switch(optionValue) {
          case 'Room':
          updateValue = 'Room';
          break;
          case 'Square Foot':
          updateValue = "SF";
          break;
          }
          spanText.innerHTML = updateValue;
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 18:16









          claireckcclaireckc

          807




          807

























              0














              First of all PHP is a server site script. It runs on the server then return the results. Thats all. There is nothing else between your browser and server after get the response.



              Every time when you run a .PHP the page will be loading and waiting for server's response. You can't do anything on page before site loaded. So if you want get real time update from server (Without refresh/reload site) You should make a background connection (Web-Socket) Or you should ask server for any updates frequently in background (AJAX)



              So here you should make a background connection to server using Javascript. Its a client side, It will connect client and server.



              This is a very basic concept.. Refer this links to learn



              Ajax request Websoket






              share|improve this answer




























                0














                First of all PHP is a server site script. It runs on the server then return the results. Thats all. There is nothing else between your browser and server after get the response.



                Every time when you run a .PHP the page will be loading and waiting for server's response. You can't do anything on page before site loaded. So if you want get real time update from server (Without refresh/reload site) You should make a background connection (Web-Socket) Or you should ask server for any updates frequently in background (AJAX)



                So here you should make a background connection to server using Javascript. Its a client side, It will connect client and server.



                This is a very basic concept.. Refer this links to learn



                Ajax request Websoket






                share|improve this answer


























                  0












                  0








                  0







                  First of all PHP is a server site script. It runs on the server then return the results. Thats all. There is nothing else between your browser and server after get the response.



                  Every time when you run a .PHP the page will be loading and waiting for server's response. You can't do anything on page before site loaded. So if you want get real time update from server (Without refresh/reload site) You should make a background connection (Web-Socket) Or you should ask server for any updates frequently in background (AJAX)



                  So here you should make a background connection to server using Javascript. Its a client side, It will connect client and server.



                  This is a very basic concept.. Refer this links to learn



                  Ajax request Websoket






                  share|improve this answer













                  First of all PHP is a server site script. It runs on the server then return the results. Thats all. There is nothing else between your browser and server after get the response.



                  Every time when you run a .PHP the page will be loading and waiting for server's response. You can't do anything on page before site loaded. So if you want get real time update from server (Without refresh/reload site) You should make a background connection (Web-Socket) Or you should ask server for any updates frequently in background (AJAX)



                  So here you should make a background connection to server using Javascript. Its a client side, It will connect client and server.



                  This is a very basic concept.. Refer this links to learn



                  Ajax request Websoket







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 17:59









                  Banujan BalendrakumarBanujan Balendrakumar

                  7691212




                  7691212






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435805%2fupdating-display-from-php-if-statement-live%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python