Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Form arrays in javascript
Old 06-05-2007, 04:47 AM Form arrays in javascript
Extreme Talker

Posts: 196
Trades: 0
Why wont this work? checkFields() iF statment is failing. The select must be set to multiple. Thanks.

Code:
<form method="POST" action="" name="this_form" onSubmit="return checkFields();">
    <select name="this_select[]" multiple>
        <option value="ts1">ts1</option>
        <option value="ts2">ts2</option>
        <option value="ts3">ts3</option>
        <option value="ts4">ts4</option>
    </select>
</form>

Code:
<script language="Javascript">
<!--
function checkFields(){
    var errormsg = "";
    if (document.this_form.this_select.value == "") { var errormsg = errormsg + "Please Select an Value.\n\r"; }
    if (errormsg != "") { alert(errormsg); return false; }
}
//-->
</script>

Last edited by empiresolutions; 06-05-2007 at 05:15 AM..
empiresolutions is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-05-2007, 01:57 PM Re: Form arrays in javascript
Extreme Talker

Posts: 196
Trades: 0
solution:
Code:
document.this_form.elements['this_select[]'].value
empiresolutions is offline
Reply With Quote
View Public Profile
 
Old 06-05-2007, 02:43 PM Re: Form arrays in javascript
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
or this may also work:

document.this_form.this_select[0].value
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-06-2007, 02:34 PM Re: Form arrays in javascript
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
If you change to add an id:
HTML Code:
<form method="POST" action="" name="this_form" onSubmit="return checkFields();">
    <select name="this_select[]" id="this_select[]" multiple>
        <option value="ts1">ts1</option>
        <option value="ts2">ts2</option>
        <option value="ts3">ts3</option>
        <option value="ts4">ts4</option>
    </select>
</form>
Then, you can use
Code:
<script language="Javascript">
<!--
function checkFields(){
    var errormsg = "";
    if (document.getElementById('this_select[]').options[ document.getElementById('this_select[]').options.selectedIndex].value == "") { var errormsg = errormsg + "Please Select an Value.\n\r"; }
    if (errormsg != "") { alert(errormsg); return false; }
}
//-->
</script>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-06-2007, 06:10 PM Re: Form arrays in javascript
Extreme Talker

Posts: 196
Trades: 0
thanks. this is probably more cross browser friendly.
empiresolutions is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Form arrays in javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.58670 seconds with 12 queries