473,322 Members | 1,566 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,322 software developers and data experts.

Form arrays in javascript

162 100+
Why wont this work? checkFields() iF statment is failing. The select must be set to multiple. Thanks.

Expand|Select|Wrap|Line Numbers
  1. <form method="POST" action="" name="this_form" onSubmit="return checkFields();">
  2.     <select name="this_select[]" multiple>
  3.         <option value="ts1">ts1</option>
  4.         <option value="ts2">ts2</option>
  5.         <option value="ts3">ts3</option>
  6.         <option value="ts4">ts4</option>
  7.     </select>
  8. </form>
  9.  

Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2. <!--
  3. function checkFields(){
  4.     var errormsg = "";
  5.     if (document.this_form.this_select.value == "") { var errormsg = errormsg + "Please Select an Value.\n\r"; }
  6.     if (errormsg != "") { alert(errormsg); return false; }
  7. }
  8. //-->
  9. </script>
  10.  
Jun 5 '07 #1
7 1329
empiresolutions
162 100+
.................................
Jun 5 '07 #2
dmjpro
2,476 2GB
Hello .....

what do u mean by this ....

Expand|Select|Wrap|Line Numbers
  1. <select name="this_select[]" multiple>
  2.  
???

Kind regards,
Dmjpro.
Jun 5 '07 #3
acoder
16,027 Expert Mod 8TB
Give your select an id and access it using
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('selId');
Jun 5 '07 #4
acoder
16,027 Expert Mod 8TB
.................................
Ok, I give up! What does this mean?
Jun 5 '07 #5
empiresolutions
162 100+
solution:
Expand|Select|Wrap|Line Numbers
  1. document.this_form.elements['this_select[]'].value
Jun 5 '07 #6
dmjpro
2,476 2GB
solution:
Expand|Select|Wrap|Line Numbers
  1. document.this_form.elements['this_select[]'].value
Hello ................this_select[]
this is not a valid name ....Right?

Kind regards,
Dmjpro.
Jun 6 '07 #7
acoder
16,027 Expert Mod 8TB
Hello ................this_select[]
this is not a valid name ....Right?
I think it's used for PHP on the server side, IIRC.

You can't normally access it using Javascript, except as he has managed to do.
Jun 6 '07 #8

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

Similar topics

12
by: szar | last post by:
I'm passing numerous array elements called list when a form is submitted. the brackets are necessary for PHP to see all the values as an array. The problem is I can't seem to reference the form...
2
by: Greg Bryant | last post by:
I'm working on a page generated by PHP, and all the form fields are named as b. (e.g. <input type=text name='b' value='Adam'>). Javascript seems to barf on this (document.formname.b.length is...
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
18
by: lawrence | last post by:
If I'm pretty sure there is just one form on the page, can i do this? var myForm = document.forms; If I'm not sure about the form, is it safer to do this? if (document.forms) { var myForm =...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
34
by: Christopher Benson-Manica | last post by:
If an array is sparse, say something like var foo=; foo=4; foo='baz'; foo='moo'; is there a way to iterate through the entire array? --
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
11
by: oliver.saunders | last post by:
I'm looking for help with project. I have written a detailed post about it. Please see: http://forums.devnetwork.net/viewtopic.php?t=52753
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
15
by: Kevin Davis | last post by:
Hello, I'm a new person when it comes to PHP and I have a quick question. I would like to create a form that will allow the user to add more information using the same form in case they have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.