I have Checkboxes, the last checkbox is OTHER if the user clicks it, a textbox will appear. I want to get the value of the textbox and pass it on my checkbox, I do not know how to do it. This is my code, I used loop to get the checked checkbox, and check if textbox is empty. I hope you can understand this. Thank You!

$n = count($_SESSION['sch']);
    $schp="";
for($i=0;$i<$n; $i++)
{
    $schp .= $_SESSION['sch'][$i]. "; ";
}

    echo $schp;

if (empty($_POST['txtOSch'])){
    echo 'a';
}
else{
    $_SESSION['txtOSch'] = $_POST['txtOSch'];
    echo $_SESSION['txtOSch'];
}

Recommended Answers

All 5 Replies

I'm sorry but I find it kind of hard to understand your question :p. Is what you're asking: 'How do I pass the value of a textarea to a checkbox WHILE staying on the same page?' If yes, I'd say you'd have to use Javascript for that. If not, could you maybe rephrase your question?

Im sorry, Im getting all the values from another page, so I'm using session. Sorry for that.

So there's a textarea on page A, and a checkbox on page B, and a value from page A needs to be passed on to page B and given to a checkbox?

There are checkboxes(5) and textbox(1) in Page A, if the last check box is checked a textbox will appear, the value on that textbox will be passed on the checkbox (or any means to get the value of the textbox).

After that I want the value to be passed on Page B. Thank You!

Well, let's say you have this setup:

<input type="checkbox" name="a_checkbox0" value="a_value0">
<input type="checkbox" name="a_checkbox1" value="a_value1">
<input type="checkbox" name="a_checkbox2" value="a_value2">
<input type="checkbox" name="a_checkbox3" value="a_value3">
<input type="checkbox" name="a_checkbox4" value="a_value4">
<textarea name="a_textarea"></textarea>

Then on your PHP page, you could easily access the value of the textarea (once the form is submitted), and use that value instead of the value of your checkbox? Like:

<?php
$last_checkbox_value = $_POST['a_checkbox4'];
$textbox_value = $_POST['a_textarea'];

// Use $textbox_value instead of $last_checkbox_value if you want that value.
// ..

Or do you want the checkbox to obtain the value of the textarea BEFORE the form is submitted?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.