php submit button disabled if want to edit data [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i got a problem where , if i want to edit the data the submit button is disabled . by the way , the data already exist but we want to edit some field e.g : id_no etc (use autocomple script)
this is the function to validate the data .
function validate()
{
if((\$('txt_no_kp').value != '')
&& (\$('txt_nama').value != '')
&& (\$('txt_alamat').value != ''))
{
\$('btn_basic').disabled = false;
}
else
{
\$('btn_basic').disabled = true;
}
}
this is the form php
<td colspan="2">
<strong>Name</strong>
<div id="div_nama">
<input name="txt_nama" type="text" id="txt_nama" onchange="validate()" size="40" />
</div>
</td>
<td colspan="2">
<strong>Alamat</strong><br />
<div id="div_alamat">
<textarea name="txt_alamat" id="txt_alamat" cols="40" rows="3" onchange="validate()"></textarea>
</div>
</td>
here the button coding :
<input type="submit" name="btn_basic" id="btn_basic" value="Simpan" />

Please try below code :
function validate()
{
if(($('#txt_no_kp').value != '')
&& ($('#txt_nama').value != '')
&& ($('#txt_alamat').value != ''))
{
$('#btn_basic').prop('disabled',false);
}
else
{
$('#btn_basic').prop('disabled',true);
}
}

Related

if check box checked active text field PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
first textfield should be disabled and when i clicked on check box, textfield should be active.
echo'<input type="checkbox" name="checkbox"/>';
echo'<textarea name="explain" id="explain"
cols="" rows="" style="width:300 ;height:300"></textarea>
if(isset($_POST['checkbox']))
{
???
}
I think you should use this:
<form>
<input type="checkbox" name="checkbox" onchange="toggleDisabled(this.checked)"/>
<textarea name="explain" id="explain"></textarea>
</form>
<script>
function toggleDisabled(checked) {
document.getElementById('explain').disabled = checked ? false : true;
}
</script>
Full code is here
Your question a little unclear. I've interpreted this as you needing JavaScript to set the textarea to disabled and active on a checkbox value without going to the server.
Using Javascript you can add an event listener on the checkbox and check the checked property, then set the textarea to disabled or not.
document.getElementById("checkbox").addEventListener("click", checkbox_textarea);
function checkbox_textarea() {
if( this.checked == true ) {
document.getElementById("textarea").disabled = false;
return false;
}
document.getElementById("textarea").disabled = true;
}
<input id=checkbox type=checkbox name=chk /> Enable text area <br />
<textarea id=textarea name=txt cols=50 rows=20 disabled></textarea>

Checking if textarea and input isset [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hello i want to check if the textarea isnt empty and i still can´t get the echo that i want even when the textarea isnt empty and input is set
here is my code:
<form method="post" action="">
<input type="text" name="jmeno"/>
<textarea name="textarea" id="textarea" rows="5" cols="40"></textarea>
<input type="submit" name="submit"/>
</form>
<?php
if(isset($_POST['jmeno']) AND !empty($_POST['textarea'])){
echo "dokončeno";
}
?>
How about this:
if (!is_null($_POST['jmeno']) && strlen(trim($_POST['jmeno'])) > 0) {
echo "dokončeno";
}
As far as I understand you want your code to check if the submit button is pressed and the textarea isn't empty. I would say the code is:
if(isset($_POST['jmeno'])){
if(strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
}
OR simply:
if(isset($_POST['jmeno']) && strlen($_POST['textarea']) > 0){
echo "dokončeno";
}
if (isset($_POST['jmeno']) && strlen(trim($_POST['textarea']))>0)
{
echo "dokončeno";
}

Set all array value inside loop if they are isset [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php /* for loop starts */ ?>
<div>
<input name="cat[]" type="text" />
</div>
<?php /* for loop ends */ ?>
I want to display each value inside the input box if their POST variable is set.
try this bro :
i have a similar query like this.
<?php
$j = 0;
for($i = 1; $i<=8; $i++) {
?>
<tr>
<td style="width:50% !important;">
<input type="text" class="form-control" name="cat[]" value="<?php echo isset( $_POST['cat'][$j] ) ? $_POST['cat'][$j] : ''; ?>" />
</td>
</tr>
<?php $j++; } ?>

form post returns text [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
form.html
<form name="input" action="process.php" method="post">
<input type="text" name="user" placeholder="Enter Your Name">
<input type="text" name="message" placeholder="Enter A Message">
<br>
<input class="shout-btn" type="submit" name="submit" value="Shout It Out">
</form>
process.php
<?php
include "database.php";
echo var_dump($_POST);
if(isset($_POST['submit'])){
$user = mysqli_real_escape_string($con,$_POST['user']);
$message = mysqli_real_escape_string($con,$_POST['message']);
//SET TIMEZONE
date_default_timezone_set('America/New_York');
$time = date('h:i:s a',time());
if (!isset($user) || $user == "" || !isset($message) || $message == "") {
echo "bad";
} else {
echo "good";
}
}
?>
For some reason $_POST gives me text variable:
array(3) { ["text"]=> string(5) "david" ["message"]=> string(27) "adasdasdasdasdasd asdasdasd" ["submit"]=> string(12) "Shout It Out" }
Notice: Undefined index: user in D:\xampp\htdocs\php\shoutit\process.php on line 6
bad
Either you've retyped form.html correctly on SO and there is an error in you actual code (mainly calling the name field text), or you had it like this, then fixed it and the your browser is caching the old version.
Easy way to check, in your browser view source on the form and check the form name.
Clear your cache and try again.

How to check if the checkbox is checked or not in php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i have an if statement as follows
if($_POST['remember']=="on")
i want to know if this is the correct syntax for checking if the checkbox is checked or unchecked?
This code will help you
<input type="checkbox" name="checkbx" <?php if(isset($_POST['remember'])=="on") echo "checked";?> />
OR
<?php if(isset($_POST['remember'])=="on") {?>
<input type="checkbox" name="checkbx" checked="checked" />
<?php }else {?>
<input type="checkbox" name="checkbx" />
<?php }?>
simple check of isset
if(isset($_POST['remember']) && $_POST['remember']=="on")
{
// checkbox remember is checked
}
else
{
// checkbox remember is not checked
}
Use
if (isset($_POST['remember'])) {
// checked
} else {
not checked
}
<input type="checkbox" name="remember" value="YES" />
$remember= ($_POST['remember'] == 'YES')?'YES':'NO';

Categories