|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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'; |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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? |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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? |
|
#7
|
|||
|
|||
|
Thanks
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > problem in javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|