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>
Related
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 last month.
Improve this question
I need to make a text that can be edited by user but in some parts I need to make static text for example the date and ....,how to make it ,plz can anyone help me
I have tried the normal input but it did not work as I expected
you can define editable part in page for each section, after type in input with js concatenation all text in main input, and in submit just pass main text to back-end.
like bellow:
<input type="hidden" name="text" id="main-text-id">
<input class="text-part" type="text">
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
...
and your script :
<script>
const mainText = document.getElementById('main-text-id');
const inputs = document.querySelectorAll('.text-part');
inputs.forEach(input => {
input.addEventListener('input', () => {
mainText.value = Array.from(inputs).map(input => input.value).join(' ');
});
});
</script>
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 2 years ago.
Improve this question
I have a bit of a problem. I have element with form::input in it. And i want to get lebel text and input value at the same time and pass it to another element as value.
For ex.
<label for="contact">Only contact if the fee is over <input id="jpy" min="0" name="JPY" type="number" value=""> JPY(Include tax)
</label>
What i want to achieve is to pass "Only contact if the fee is over 1000 JPY(Include tax)" as a value to another element.
I know how to get .text() of label element and i know how to get value from input. But i don't know how to get them at the same time in consistent form.
You can use .contents(), but a better approach would be to use label tag correctly:
$('button').on('click', () => {
let contents = $('label').contents()
console.log(contents[0].wholeText + $(contents[1]).val() + contents[2].wholeText)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="contact">Only contact if the fee is over <input id="jpy" min="0" name="JPY" type="number" value=""> JPY(Include tax)
</label>
<button id="button">Get text</button>
$('button').on('click', () => {
var label = $('label[for="contact"]').text();
var input = $('#jpy').val();
console.log(label+' '+input);
});
Hope this works
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";
}
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
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
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';