General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 16th, 2004, 06:53 AM
devendraC devendraC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 11 devendraC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry problem in javascript

Hi I am posting multiple values from selection box(multi selection combo-box) to php and getting javascript error.
Detail:-

<select name="combo1[]" multiple>
....
Now there is Java-Script error when I call:-
document.frm1.combo1.selectedIndex='2';
Error:-
document.frm1.combo1 is null or not an object

I also tried as but get same error:-
document.frm1.combo1[].selectedIndex='2';

Reply With Quote
  #2  
Old January 16th, 2004, 09:10 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
First off, this is part of a double post, and this should have been posted in the Javascript forum, not PHP


However, why are you declaring the sselect box as an array?

Do you want multiple select boxes, or multiple values for one box?

Either take out the [] in the select's name...
or try document.frm1.combo1[0].selectedIndex


Reply With Quote
  #3  
Old January 17th, 2004, 12:32 AM
devendraC devendraC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 11 devendraC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,
It is a common practice in php to receive multiple values from a selection box by using combo1[].

I also tried,
document.frm1.combo1[0].selectedIndex
but no gain.

Please help

Reply With Quote
  #4  
Old January 17th, 2004, 11:15 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I don't understand... is your problem a javascript problem, or PHP?

In PHP you would call it via $_POST['combo[0]']
In Javascript you should be able to call it with document.frm1.combo1[0].selectedIndex

JAvascript may not interpret the array of select boxes properly... i bet that's messing it up... its generally not a good idea to include [] in the object's name... is there a specific reason you've done that?

Do you want multiple select boxes, or multiple values from one box?

Reply With Quote
  #5  
Old January 18th, 2004, 12:21 AM
devendraC devendraC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 11 devendraC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,
I want multiple values from one box and my problem is relating to javascript.

when I am including [] in the object name,I am able to get all selected values of combo-box in PHP,but before it I get javascript error even if I use document.frm1.combo1[0].selectedIndex

Reply With Quote
  #6  
Old January 18th, 2004, 03:36 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
wait a second... the problem isn't how you're calling it... its how you're getting the selectedIndex... if there's multiple selected indexes, selectedIndex isn't exactly defined...

Here's a sample script I found from the PHPBuilder forum:
Code:
<html> 
<head> 
    <title>test.html</title> 
     
<script type="text/javascript" language="javascript"> 


function showMe() { 
    var thisForm = document.myForm.mySelect; 
    var tVar = ''; 
    // get the selection list length and run through it 
    for (var zCnt = 0; zCnt < thisForm.options.length; zCnt++) { 
        // check to see if each item is selected 
        if (thisForm.options[zCnt].selected) { 
             // first item in the list needs no delimiter 
            if (tVar == '') { 
                tVar = thisForm.options[zCnt].value; 
                } else { 
                tVar += ':' + thisForm.options[zCnt].value; 
                } 
            } 
        } 
    // what did we find? 
    window.status = 'current tVar value today is => ' + tVar; 
    } 



</script> 


</head> 
<body> 
<form name='myForm'> 
<select name="mySelect" size="5" multiple> 
    <option label="0" value="0">0</option> 
    <option label="1" value="1">1</option> 
    <option label="2" value="2">2</option> 
    <option label="3" value="3">3</option> 
    <option label="4" value="4">4</option> 
    </select> 
<input type='button' value='show me' onClick='javascript:showMe();') 
</form> 
</body> 
</html> 


Perhaps that will help you?

Reply With Quote
  #7  
Old January 18th, 2004, 11:19 PM
devendraC devendraC is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 11 devendraC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > problem in javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT