Can you please help me how to loop a textbox

for example, I have 10 checkboxes and I check only 2 of them. If I click the submit button, the number of times I check a checkbox should be the number of textboxes to display..

so I check 2 checkboxes from the total of 10.. so it must also display 2 textboxes upon clicking submit button..

Thank you very Much/.. Hope you can help me... I really dont have a clue..

Recommended Answers

All 6 Replies

Let suppose you have 10 check boxes like this

<input type="checkbox" name="chk[]" value="anyvalue1">
<input type="checkbox" name="chk[]" value="anyvalue2">
<input type="checkbox" name="chk[]" value="anyvalue3">
...
<input type="checkbox" name="chk[]" value="anyvalue4">

You can use following PHP code to finc dout the number of selected check boxes

$allChecks = $_POST['chk'];

$noOfChecked = count($allChecks);

// print the values of selected check boxes

for($i=0; $i<$noOdChecked; $i++)
{
        echo $allChecks[$i]."<br>";
}

Let suppose you have 10 check boxes like this

<input type="checkbox" name="chk[]" value="anyvalue1">
<input type="checkbox" name="chk[]" value="anyvalue2">
<input type="checkbox" name="chk[]" value="anyvalue3">
...
<input type="checkbox" name="chk[]" value="anyvalue4">

You can use following PHP code to finc dout the number of selected check boxes

$allChecks = $_POST['chk'];

$noOfChecked = count($allChecks);

// print the values of selected check boxes

for($i=0; $i<$noOdChecked; $i++)
{
        echo $allChecks[$i]."<br>";
}

Tnx for the info.. but I want to display textboxes... for example I check 2 so it must also display 2 textboxes....

I want to display textboxes..


for example, out of the 6 checkboxes, i only check 2 of them..

so upon clicking the submit button, it must also display 2 textbox

You can print any thing inside the loop. It will run number of times equal to the number of checked check boxes

$allChecks = $_POST['chk']; 

$noOfChecked = count($allChecks); 

for($i=0; $i<$noOfChecked; $i++)
{        
//print text boxes
echo "<input type=text name=text_$i><br/>";
}

I think he want's it AJAX, onClick="show_2_more_boxes()"

the problem is you need someone to write that function :P Cuz i don't understand much of ajax!

@ dasatti - thank you very much... you're really a great help for me...

thnx..

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.