![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 874
Rep Power: 4
![]() |
You are almost there. Change
<select name="contact[]" multiple> You didn't show how you were calling the validation function. Is that working? |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 122
Rep Power: 4
![]() |
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" |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
Thanx a lot Agent 47.
It works very well :-)! Do you know the best web ressources for javascript ??? Thank! |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Nov 2005
Posts: 122
Rep Power: 4
![]() |
Quote:
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" |
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jan 2006
Posts: 17
Rep Power: 0
![]() |
Thank you Agent 47
those website are incredible ! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|