Jump to content

Adding text box on demand


houssam_ballout

Recommended Posts

Helo all,

 

I am building an applications using php, I'd created a page where the user can add questions. I gave him the option to add different answers by selecting the number of options from a drop-down box.

The code below is running but I'd to click the button to add my number of boxes, I want to make in a way , that when I select the number of boxes from the drop-down to create it automatically (in other way, call the form submit automatically)?

Thanks in advance

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

 

<body>

 

<?php

 

if(isset($_POST['select']))

{

 

$number = $_POST['NbOptions'];

 

for($i=0;$i<$number;$i++)

 

echo "<input type='text' name='option$i' /><br />";

 

 

}

 

 

 

?>

 

<form name="test" method="post">

 

<select name="NbOptions">

<option>1</option>

<option>2</option>

<option>3</option>

<option>4</option>

<option>5</option>

<option>6</option>

<option>7</option>

</select>

<input type="submit" name="select" />

 

</form>

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/87853-adding-text-box-on-demand/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.