Auto fill on input with javascript









up vote
1
down vote

favorite












if user input this field



<input class="form-control" type="date"
name="tgl_selesai"
value="<?php echo htmlentities($row_inq['tgl_selesai'],
ENT_COMPAT, 'utf-8'); ?>"
size="32"><br>


Then automaticly this field will be fill



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed")))
echo "checked="checked"";

?>> Closed
<input type="radio" name="status" value="On Progres"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'),"On Progres")))
echo "checked="checked"";

?>> On Progres
</label>


if user input = closed










share|improve this question























  • @Amessihel if user input the date field, the radio button will automatically fill as Closed
    – Farrel Anelca
    Nov 9 at 10:03










  • mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
    – Farrel Anelca
    Nov 10 at 9:22











  • There is no question here.
    – trincot
    Nov 10 at 20:29










  • @trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
    – Amessihel
    Nov 10 at 20:54














up vote
1
down vote

favorite












if user input this field



<input class="form-control" type="date"
name="tgl_selesai"
value="<?php echo htmlentities($row_inq['tgl_selesai'],
ENT_COMPAT, 'utf-8'); ?>"
size="32"><br>


Then automaticly this field will be fill



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed")))
echo "checked="checked"";

?>> Closed
<input type="radio" name="status" value="On Progres"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'),"On Progres")))
echo "checked="checked"";

?>> On Progres
</label>


if user input = closed










share|improve this question























  • @Amessihel if user input the date field, the radio button will automatically fill as Closed
    – Farrel Anelca
    Nov 9 at 10:03










  • mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
    – Farrel Anelca
    Nov 10 at 9:22











  • There is no question here.
    – trincot
    Nov 10 at 20:29










  • @trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
    – Amessihel
    Nov 10 at 20:54












up vote
1
down vote

favorite









up vote
1
down vote

favorite











if user input this field



<input class="form-control" type="date"
name="tgl_selesai"
value="<?php echo htmlentities($row_inq['tgl_selesai'],
ENT_COMPAT, 'utf-8'); ?>"
size="32"><br>


Then automaticly this field will be fill



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed")))
echo "checked="checked"";

?>> Closed
<input type="radio" name="status" value="On Progres"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'),"On Progres")))
echo "checked="checked"";

?>> On Progres
</label>


if user input = closed










share|improve this question















if user input this field



<input class="form-control" type="date"
name="tgl_selesai"
value="<?php echo htmlentities($row_inq['tgl_selesai'],
ENT_COMPAT, 'utf-8'); ?>"
size="32"><br>


Then automaticly this field will be fill



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed")))
echo "checked="checked"";

?>> Closed
<input type="radio" name="status" value="On Progres"
<?php
if (!(strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'),"On Progres")))
echo "checked="checked"";

?>> On Progres
</label>


if user input = closed







javascript php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 11:52









Amessihel

1,7151623




1,7151623










asked Nov 9 at 9:54









Farrel Anelca

62




62











  • @Amessihel if user input the date field, the radio button will automatically fill as Closed
    – Farrel Anelca
    Nov 9 at 10:03










  • mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
    – Farrel Anelca
    Nov 10 at 9:22











  • There is no question here.
    – trincot
    Nov 10 at 20:29










  • @trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
    – Amessihel
    Nov 10 at 20:54
















  • @Amessihel if user input the date field, the radio button will automatically fill as Closed
    – Farrel Anelca
    Nov 9 at 10:03










  • mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
    – Farrel Anelca
    Nov 10 at 9:22











  • There is no question here.
    – trincot
    Nov 10 at 20:29










  • @trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
    – Amessihel
    Nov 10 at 20:54















@Amessihel if user input the date field, the radio button will automatically fill as Closed
– Farrel Anelca
Nov 9 at 10:03




@Amessihel if user input the date field, the radio button will automatically fill as Closed
– Farrel Anelca
Nov 9 at 10:03












mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
– Farrel Anelca
Nov 10 at 9:22





mysql_select_db($database_koneksi, $koneksi); $query_inq = "SELECT * FROM inquiry"; $inq = mysql_query($query_inq, $koneksi) or die(mysql_error()); $row_inq = mysql_fetch_assoc($inq); $totalRows_inq = mysql_num_rows($inq); @Amessihel
– Farrel Anelca
Nov 10 at 9:22













There is no question here.
– trincot
Nov 10 at 20:29




There is no question here.
– trincot
Nov 10 at 20:29












@trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
– Amessihel
Nov 10 at 20:54




@trincot: OP wants the status set to Closed if a date ("tgl_selesai") is filled. Maybe an edit could clarify the question.
– Amessihel
Nov 10 at 20:54












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The extension mysql_fetch_assoc() returns for the current line an associative array pairing a column name with its value. You can check if a value is NULL (ie a column is not filled) with the function is_null().



This answer is based on the code you posted in a comment:



$query_inq = "SELECT * FROM inquiry";
$inq = mysql_query($query_inq, $koneksi) or die(mysql_error());
$row_inq = mysql_fetch_assoc($inq);
$totalRows_inq = mysql_num_rows($inq)


Below we store in a boolean variable if the status is closed:



// Status is closed if $row_inq['status'] equals "Closed" **OR**
// the date thgl_selesai is filled
$isClosedStatus =
strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed") == 0 ||
is_null($row_inq['tgl_selesai']);


(I assumed it was the case if the status in the base is set as "Closed" OR if the date tgl_selesai is filled; if it is not the case, editing the code is not very difficult.)



Finally, our HTML becomes:



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php echo $isClodedStatus?"checked":"") ?>> Closed
<input type="radio" name="status" value="On Progres"
<?php echo $isClodedStatus?"":"checked") ?>> On Progres
</label>


As you can notice, using a variable makes the code above way easier to read.



Note: the official PHP manual says that mysql_fetch_assoc is deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Click on the link to read more about this issue.






share|improve this answer






















  • sbb, i will tyr to use, thank you before
    – Farrel Anelca
    Nov 12 at 16:35











  • Some news about this answer? Does it suit your question?
    – Amessihel
    6 hours ago










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',
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%2f53223451%2fauto-fill-on-input-with-javascript%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The extension mysql_fetch_assoc() returns for the current line an associative array pairing a column name with its value. You can check if a value is NULL (ie a column is not filled) with the function is_null().



This answer is based on the code you posted in a comment:



$query_inq = "SELECT * FROM inquiry";
$inq = mysql_query($query_inq, $koneksi) or die(mysql_error());
$row_inq = mysql_fetch_assoc($inq);
$totalRows_inq = mysql_num_rows($inq)


Below we store in a boolean variable if the status is closed:



// Status is closed if $row_inq['status'] equals "Closed" **OR**
// the date thgl_selesai is filled
$isClosedStatus =
strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed") == 0 ||
is_null($row_inq['tgl_selesai']);


(I assumed it was the case if the status in the base is set as "Closed" OR if the date tgl_selesai is filled; if it is not the case, editing the code is not very difficult.)



Finally, our HTML becomes:



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php echo $isClodedStatus?"checked":"") ?>> Closed
<input type="radio" name="status" value="On Progres"
<?php echo $isClodedStatus?"":"checked") ?>> On Progres
</label>


As you can notice, using a variable makes the code above way easier to read.



Note: the official PHP manual says that mysql_fetch_assoc is deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Click on the link to read more about this issue.






share|improve this answer






















  • sbb, i will tyr to use, thank you before
    – Farrel Anelca
    Nov 12 at 16:35











  • Some news about this answer? Does it suit your question?
    – Amessihel
    6 hours ago














up vote
0
down vote













The extension mysql_fetch_assoc() returns for the current line an associative array pairing a column name with its value. You can check if a value is NULL (ie a column is not filled) with the function is_null().



This answer is based on the code you posted in a comment:



$query_inq = "SELECT * FROM inquiry";
$inq = mysql_query($query_inq, $koneksi) or die(mysql_error());
$row_inq = mysql_fetch_assoc($inq);
$totalRows_inq = mysql_num_rows($inq)


Below we store in a boolean variable if the status is closed:



// Status is closed if $row_inq['status'] equals "Closed" **OR**
// the date thgl_selesai is filled
$isClosedStatus =
strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed") == 0 ||
is_null($row_inq['tgl_selesai']);


(I assumed it was the case if the status in the base is set as "Closed" OR if the date tgl_selesai is filled; if it is not the case, editing the code is not very difficult.)



Finally, our HTML becomes:



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php echo $isClodedStatus?"checked":"") ?>> Closed
<input type="radio" name="status" value="On Progres"
<?php echo $isClodedStatus?"":"checked") ?>> On Progres
</label>


As you can notice, using a variable makes the code above way easier to read.



Note: the official PHP manual says that mysql_fetch_assoc is deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Click on the link to read more about this issue.






share|improve this answer






















  • sbb, i will tyr to use, thank you before
    – Farrel Anelca
    Nov 12 at 16:35











  • Some news about this answer? Does it suit your question?
    – Amessihel
    6 hours ago












up vote
0
down vote










up vote
0
down vote









The extension mysql_fetch_assoc() returns for the current line an associative array pairing a column name with its value. You can check if a value is NULL (ie a column is not filled) with the function is_null().



This answer is based on the code you posted in a comment:



$query_inq = "SELECT * FROM inquiry";
$inq = mysql_query($query_inq, $koneksi) or die(mysql_error());
$row_inq = mysql_fetch_assoc($inq);
$totalRows_inq = mysql_num_rows($inq)


Below we store in a boolean variable if the status is closed:



// Status is closed if $row_inq['status'] equals "Closed" **OR**
// the date thgl_selesai is filled
$isClosedStatus =
strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed") == 0 ||
is_null($row_inq['tgl_selesai']);


(I assumed it was the case if the status in the base is set as "Closed" OR if the date tgl_selesai is filled; if it is not the case, editing the code is not very difficult.)



Finally, our HTML becomes:



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php echo $isClodedStatus?"checked":"") ?>> Closed
<input type="radio" name="status" value="On Progres"
<?php echo $isClodedStatus?"":"checked") ?>> On Progres
</label>


As you can notice, using a variable makes the code above way easier to read.



Note: the official PHP manual says that mysql_fetch_assoc is deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Click on the link to read more about this issue.






share|improve this answer














The extension mysql_fetch_assoc() returns for the current line an associative array pairing a column name with its value. You can check if a value is NULL (ie a column is not filled) with the function is_null().



This answer is based on the code you posted in a comment:



$query_inq = "SELECT * FROM inquiry";
$inq = mysql_query($query_inq, $koneksi) or die(mysql_error());
$row_inq = mysql_fetch_assoc($inq);
$totalRows_inq = mysql_num_rows($inq)


Below we store in a boolean variable if the status is closed:



// Status is closed if $row_inq['status'] equals "Closed" **OR**
// the date thgl_selesai is filled
$isClosedStatus =
strcmp(htmlentities($row_inq['status'], ENT_COMPAT, 'utf-8'), "Closed") == 0 ||
is_null($row_inq['tgl_selesai']);


(I assumed it was the case if the status in the base is set as "Closed" OR if the date tgl_selesai is filled; if it is not the case, editing the code is not very difficult.)



Finally, our HTML becomes:



<label>Status Inquiry:</label><br>
<label>
<input type="radio" name="status" value="Closed"
<?php echo $isClodedStatus?"checked":"") ?>> Closed
<input type="radio" name="status" value="On Progres"
<?php echo $isClodedStatus?"":"checked") ?>> On Progres
</label>


As you can notice, using a variable makes the code above way easier to read.



Note: the official PHP manual says that mysql_fetch_assoc is deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. Click on the link to read more about this issue.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 20:21

























answered Nov 10 at 18:59









Amessihel

1,7151623




1,7151623











  • sbb, i will tyr to use, thank you before
    – Farrel Anelca
    Nov 12 at 16:35











  • Some news about this answer? Does it suit your question?
    – Amessihel
    6 hours ago
















  • sbb, i will tyr to use, thank you before
    – Farrel Anelca
    Nov 12 at 16:35











  • Some news about this answer? Does it suit your question?
    – Amessihel
    6 hours ago















sbb, i will tyr to use, thank you before
– Farrel Anelca
Nov 12 at 16:35





sbb, i will tyr to use, thank you before
– Farrel Anelca
Nov 12 at 16:35













Some news about this answer? Does it suit your question?
– Amessihel
6 hours ago




Some news about this answer? Does it suit your question?
– Amessihel
6 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223451%2fauto-fill-on-input-with-javascript%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線