0

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..

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by venus_me11
0

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>";
}
0

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....

0

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

0

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/>";
}
0

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!

0

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

thnx..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.