I've pulled together an online form that creates a number of tables dependant on the results of a dropdown list, i.e. 2 from the list creates two input tables, 10 creates 10 tables etc.
The script for creating the tables is as follows; - <script type="text/javascript"><!--
-
function fboxes(NumberOfBoxes){
-
var i,boxes='';
-
for(i=0; i<NumberOfBoxes; i++){
-
boxes += "<table width='400' border='0' cellspacing='0' cellpadding='0' align='left'><tr><td><strong>Location</strong></td><td><input type='textarea' name='locbox["+i+"]' id='locbox["+i+"]' size='30'></td></tr><tr><td colspan='2'><div align='center'><strong>Incident Details</strong></div></td></tr><tr><td colspan='2'><textarea name='textbox["+i+"]' id='textbox["+i+"]' cols='35' rows='8'></textarea></td></tr><tr><td colspan='2'><div align='center'><strong>Business Impact</strong></div></td></tr><tr><td colspan='2'><textarea name='bimpbox["+i+"]' id='bimpbox["+i+"]' cols='35' rows='8'></textarea></td></tr></table>";
-
}
-
document.getElementById('currentissues').innerHTML = boxes;
-
}
-
-
--></script>
This is fine and the php page that is actioned upon validation can see the information from all the various tables.
What i need though is some validation for the boxes, namely, that if there is a table then the locbox[] field has to have text in it.
Each time I've tried to write the validation part for this section it says that "locbox" isn't defined, yest it is (as in the script above).
Any help at clearing this up and simplifying arrays would be greatly, muchly, enormously appreciated.
9 1648
This would be JavaScript, wouldn't it? Ask in the JavaScript Forum! You know, Java isn't the same as JavaScript! ^^
Moved to Javascript forum
gits 5,390
Recognized Expert Moderator Expert
hi ...
how did you try to retrieve the textbox-values? to retrieve it the right way you should use for example: -
var box_value = document.getElementById('locbox[1]').value;
-
note: you cannot use locbox as an array or variable it is a simple string that is assigned to an elements id-attribute (respectivly its id-property too).
kind regards
I tried this for the validation; - var total="";
-
for(var i=0; i < locbox; i++){
-
if(locbox[i].value =="") {
-
total +=document.locbox[i].value + "\n";
-
}
-
}
-
if(total=="") {
-
alert("fill something in");
-
return false;
-
}
(I've put the whole form here http://www.eds.shed.googlepages.com/morningstatus.html if you want to take a look and it includes the wrong validation)
note: you cannot use locbox as an array or variable it is a simple string that is assigned to an elements id-attribute (respectivly its id-property too).
kind regards
I don't understand why this is as the php file which runs after validation understands all of the locbox[] values as an array, why can't another script on the first page do this?
gits 5,390
Recognized Expert Moderator Expert
hmmm ... i'm confused now. where do you want to validate your values ... serverside or clientside?
hmmm ... i'm confused now. where do you want to validate your values ... serverside or clientside?
I'm validating the form clientside, hence the javascript, and using the php form to assemble the data and email it.
gits 5,390
Recognized Expert Moderator Expert
ok ... in that case you don't have defined a variable locbox for javascript since php writes the names/ids to the document and it is a simple textual attribute of the input-nodes ... you have to retrieve the values of your textboxes with dom-methods ... like i showed you ...
kind regards
ok ... in that case you don't have defined a variable locbox for javascript since php writes the names/ids to the document and it is a simple textual attribute of the input-nodes ... you have to retrieve the values of your textboxes with dom-methods ... like i showed you ...
kind regards
So would I have to write a var line for each of the possible box variables (possibly upto 10) like this: - var box_value0 = document.getElementById('locbox[0]').value;
-
var box_value1 = document.getElementById('locbox[1]').value;
-
etc
?
gits 5,390
Recognized Expert Moderator Expert
nope ... you may do something like the following: - var value_to_check;
-
var boxes = document.getElementsByTagName('input');
-
-
for (var i = 0; i < boxes.length; i++) {
-
var box = boxes[i];
-
-
if (/^locbox/.test(box.id)) {
-
value_to_check = box.value;
-
// check here the value_to_check ;) the way you want,
-
// or assign the values to an array or whatever
-
}
-
}
-
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: tcarvin |
last post by:
This is going to sound stupid, but I can't get the help to work in
the Visual Studio .NET. I've tried using the help that comes with
Studio and also from the MSDN. All I get is a generic page-not-
found kinda error.
Any one else hit this?
Tom
|
by: Christina Feichter |
last post by:
Hello All
How can i start a help-file like help.chm?
Thanks
|
by: ajliang |
last post by:
How can I validate a proxy IP visit the web page?
do you have any code example?
|
by: Simon Barnett |
last post by:
Hi,
RE: Converting pages including ASP pages for XHTML
My question relates to ASP not ASP.NET - I can't find a newsgroup for ASP
and hoped it was still relevant in ASP.NET - sorry if it's not.
Problem: I am teaching myself about validating for XHTML and, upon testing a
page I get errors for the use of the 'name' attribute in form fields. It
seems that you have to replace the 'name' attribute for the 'id' attribute.
|
by: arda |
last post by:
how i can put 2d array to a pointer? In the below program i am giving a first value to output_bit and then start to a loop and putting the new values to an another array as called newdata. But as i understand from this loop the last value of the 2d array u is not put to newdata. Because of the first value of output_bit which is given in he beginning. In 1d array it is easy to solve this problem that you can put output_bit data in the for loop...
| |
by: recover |
last post by:
class Obj
{
public:
Obj(int a){}
}
class MyContainer
{
private:
Obj m_obj;
|
by: =?Utf-8?B?UGxheWE=?= |
last post by:
I am getting the following error when I try to write a value to my array.
An unhandled exception of type 'System.NullReferenceException' occurred in
EmpPrinting.exe
Additional information: Object reference not set to an instance of an object.
This error only occurs when I don't include an initial size in my
declareation (ex. DIM strArray( ) as String). If I declare an array with an
initial size (ex. DIM strArray(11) as String) then it...
|
by: kiny3k |
last post by:
hi, i have written this insert query for inserting data in database : "insert into leavemaster (leave_code,leave_desc,leave_type, leave_days, leave_valid_month, leave_amount, effective_date, max_limit, leave_num, maintain_bal, leave_encash, leave_fq, encash_limit, encash_fq, carry_frwd, negative_bal, max_encash_bal, leave_limit, holiday_lv, weekoff_lv, del_flag" & _
"values (@leave_code, @leave_desc, @leave_type, @leave_days,...
|
by: comedydave |
last post by:
Hi guys,
I'm new to ASP and need some array help.
I need to have a shopping cart. When you visit the site it creates a session and an array. When you click add to basket it adds the item ID to the array.
I can't get my head around how i allocate it an array slot and then empty out the array in the checkout. I presume i'd need a loop or something to go through each array item and print it out.
Thanks in advance,
|
by: abhilash12 |
last post by:
memory out of bound exception in javascript so pls tell me what is the reason
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |