Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 21st, 2006, 7:44 PM   #1
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Unhappy how to get jscript validation with <select name=test[]>

Hi,

I don't have much experience in javascript and I want to validate a form.

here is a sample of the form :

[html]
<form name="frmPoste" action="test.php" onsubmit="return formValidation(this)">
<select name="contact[]" multiple>
<option value="0">add a new contact</option>
</select>
</form>
[/html]

the javascript function I want to use:
[html]
function formValidation(form)
{
if(form.contact.options[0].selected == true)
{
// do validation for some more fields.
}
return true;
}
[/html]

My question is: How can I access the first array to know their value. If he's selected I want to do the validation for more fields.

I know the way I use ( "form.contact.options[0].selected" ) is not valid. I worked to find the correct way about 6 hours and can't find any documentation. So, if you can help me, i would appreciate very much :-)!

Thank you.
weeb0 is offline   Reply With Quote
Old May 21st, 2006, 7:53 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
You are almost there. Change
<select name="contact[]" multiple>
and remove the [] in red.

You didn't show how you were calling the validation function. Is that working?
The Dark is offline   Reply With Quote
Old May 21st, 2006, 8:12 PM   #3
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
I need the [] to receive the form in an array in my php script.

I can affirm the script work. he's called when I submit the form. I didn't write the submit button in the sample of my code.

Thank you.
weeb0 is offline   Reply With Quote
Old May 22nd, 2006, 5:05 AM   #4
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
You can use this:
if(document.frmPoste.elements['contact[]'].options[0].selected == true)
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old May 22nd, 2006, 8:31 AM   #5
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Thanx a lot Agent 47.

It works very well :-)!

Do you know the best web ressources for javascript ???

Thank!
weeb0 is offline   Reply With Quote
Old May 22nd, 2006, 8:43 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Search for Agent47's recent posts. He's made some recommendations. Button is up there ^^^^.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 22nd, 2006, 9:39 AM   #7
Agent 47
Hobbyist Programmer
 
Agent 47's Avatar
 
Join Date: Nov 2005
Posts: 122
Rep Power: 3 Agent 47 is on a distinguished road
Quote:
Originally Posted by weeb0
Thanx a lot Agent 47.

It works very well :-)!

Do you know the best web ressources for javascript ???

Thank!
If you just want the basics, then have a look at w3schools.

For more advanced stuff, check out Quirksmode.

Useful site about RegEx in JS: http://www.regular-expressions.info/javascript.html.

This is good but very advanced: http://www.sergiopereira.com/articles/prototype.js.html.
__________________
"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"
Agent 47 is offline   Reply With Quote
Old May 22nd, 2006, 9:10 PM   #8
weeb0
Newbie
 
Join Date: Jan 2006
Posts: 17
Rep Power: 0 weeb0 is on a distinguished road
Thank you Agent 47

those website are incredible !
weeb0 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:29 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC