473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Multiple Text Boxes help

I need to write a form that asks the usser to define the number of problems (this is simply from a dropdown menu), depending on the number they select they will be asked for a definition of each problem in a seperate text box (one text box for each problem). So if they pick 2 as the number of problem they will be given two text boxes, 5 boxes for selecting 5 from the drop down list.
I think I need some javascript (for form validation), some php for the form-mailer, but it's the dynamic text boxes I'm at a total loss at.
Can anyone point me in anything like the right direction?
Aug 6 '07 #1
10 2674
jx2
228 100+
but it's the dynamic text boxes I'm at a total loss at.
i recomend javascript and DHTML for that purpose
you should have something like that in your HTML - <div id='textboxes'></div>

drop down list with a numbers can call a function i wrote for you below
Expand|Select|Wrap|Line Numbers
  1. function boxes(NumberOfBoxes){
  2.      for(i=0;i<NumberOfBoxes;i++){
  3.               boxes += "<textarea name='textbox[NumberOfBoxes'></textarea>";
  4.      }
  5.               document.getElementById('textboxes').innerHTML = boxes;
  6. }
i haven test it so ...

i hope that help

jx2
Aug 6 '07 #2
I tried this;

<html>
<head>


</head>


<body>

<select name="boxes" onChange="boxes()">
<option value="">choose</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<script type="text/javascript">
function boxes(NumberOfBoxes){
for(i=0;i<NumberOfBoxes;i++){
boxes += "<textarea name='textbox[NumberOfBoxes]'></textarea>";
}
document.getElementById('textboxes').innerHTML = boxes;
}
</script>
<div id='textboxes'>
boxes should go here
</div>
</body>

</html>
and it give only one text box with loads of script showing :-(

Think I'll have another go at work tomorrow.
Aug 6 '07 #3
jx2
228 100+
<select name="boxes" onChange="boxes()">

// boxes need one parameter "number" of textboxes
// u need to pass option value to it, e.g. boxes(2);
// u might try this boxes(this.value); - i'm not sure if that will work
// but u need to pass a value somehow

regards
jx2
Aug 6 '07 #4
jx2
228 100+
i think you will like me:-)

[html]<html>
<head>


</head>


<body>

<select name="boxes" onChange="boxes(this.value)">
<option value="">choose</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<script type="text/javascript"><!--
function boxes(NumberOfBoxes){
var i,boxes='';


for(i=0; i<NumberOfBoxes; i++ ){
boxes += "<textarea name='textbox["+i+"]'></textarea>";
}
document.getElementById('textboxes').innerHTML = boxes;
}
--></script>
<div id='textboxes'>
boxes should go here
</div>
</body>

</html>[/html]

i check it!! it work very well
you'll get array textbox[]
preety cool hah

regards
jx2
Aug 6 '07 #5
No good, well this line;

<select name="boxes" onChange="boxes(this.value)">

gave internet explorer an error (Object doesn't support this property or method), firefox just didn't do anything.

Any other ideas?
Aug 7 '07 #6
jx2
228 100+
[html]<html>
<head>

<script type="text/javascript"><!--
function fboxes(NumberOfBoxes){
var i,boxes='';


for(i=0; i<NumberOfBoxes; i++ ){
boxes += "<textarea name='textbox["+i+"]'></textarea>";
}
document.getElementById('textboxes').innerHTML = boxes;
}
--></script>
</head>


<body>

<select name="boxes" onChange="fboxes(this.value)">
<option value="">choose</option>
<option value="1">1</option>
<option value="2">2</option>
</select>


<div id='textboxes'>
boxes should go here
</div>
</body>

</html>[/html]

well - i test it in IE and firefox it works very well in both of them check the syntacs of your code
i have also change the name of the function that could cos problems...
it work in my browsers
IT HAS TO WORK in yours!!!

regards
jx2
Aug 7 '07 #7
jx2
228 100+
i know what might be wrong if you copy this code from here - lines 10 and 11 should be in the same line my guess is that that might had cos your problems

regards
jx2
Aug 7 '07 #8
Fantastic! got it working, thank you very much (that saved me much hair pulling and headaches).
A further question would be how to reference the text boxes in the form-mailer php script. If I define each box

$textbox = ($_POST["textbox"]);
$textbox1 = ($_POST["textbox1"]);
$textbox2 = ($_POST["textbox2"]);

I get a result "Array,,,"

If I use $textbox["+i+"] = ($_POST["textbox["+i+"]"]);

I get nothing.

Any ideas on this part?
Aug 7 '07 #9
jx2
228 100+
A further question would be how to reference the text boxes in the form-mailer php script. If I define each box

$textbox = ($_POST["textbox"]);
$textbox1 = ($_POST["textbox1"]);
$textbox2 = ($_POST["textbox2"]);

I get a result "Array,,,"

Any ideas on this part?
well actualy , i did allready answer your question :-)
fboxes function creates textareas as an array - look at names !!! of each box $textbox[1] ,$textbox[2] and so on well its no good practise (u should use $_POST['textbox'][1]) but it simplier to explain and to use
by the way if you need to know what is in the memory print it!!!
e.g.
[php]<?php
function echovariables($variable){
echo "<ul>";
foreach($variable as $k=>$v){
echo "<li>$k =>$v </li>";
if(is_array($v)){
echovariables($v);
}
}
echo "</ul>";
}
echovariables($_POST);//can be any variable
?>
[/PHP]

if you try it u ll see what you got

regards jx2
Aug 7 '07 #10
You have been a great help, thank you. I need to brush up on php and arrays.
Aug 7 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dave Parrin-Bull | last post by:
Hi all, I have been asked (nay told!) to do a quiz for a webpage at work, now I can do the basic things like getting the radio boxes up there and assign values to them but here is what they...
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
2
by: chrisse_2 | last post by:
I currently have a form with a two text boxes and two list boxes. Now, i want the user to be able to type information into two of the text boxes and select an item from one of the list boxes; with...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
7
by: Demonicpagan | last post by:
I have this form where I am trying to place items from checked boxes into a text box. An image of what this form looks like is at http://www.stelth2000inc.com/images/screen.png Here is some...
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
4
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.