Updating display from php if statement live
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
add a comment |
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
1
As PHP runs serverside you have to do that with javascript or jquery.
– ratmalwer
Nov 22 '18 at 17:40
add a comment |
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
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
php html laravel
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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;
});
answered Nov 22 '18 at 18:16
claireckcclaireckc
807
807
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 22 '18 at 17:59
Banujan BalendrakumarBanujan Balendrakumar
7691212
7691212
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
As PHP runs serverside you have to do that with javascript or jquery.
– ratmalwer
Nov 22 '18 at 17:40