Connecting Tech Pros Worldwide Forums | Help | Site Map

how to get the value of selected option in this code

Newbie
 
Join Date: Nov 2008
Posts: 1
#1: Nov 13 '08
here in this option transfer code.after transfering data from available _services multiple box to assigned_services multiple box i am unable to get the value of the assigned_services data for ex in this
Expand|Select|Wrap|Line Numbers
  1. <option value ="0" >Admin</option>
  2. <option value ="1" >Public</option>
i am not getting 0 and 1 but i am getting admin,public



[PHP]{php} include "header2.php"; {/php}
{literal}
<link rel="stylesheet" type="text/css" href="css/styles.css" title="rsr styles" />

<script language="javascript" src="css/statechange_min.js"></script>
<script language="javascript">

function selectAllOptions(selStr)
{
var selObj = document.getElementById(selStr);
for (var i=0; i<selObj.options.length; i++) {
selObj.options[i].selected = true;

}
}

function moveoutid()
{
var sda = document.getElementById('available_services');;
var len = sda.length;
var sda1 = document.getElementById('assigned_services');
for(var j=0; j<len; j++)
{
if(sda[j].selected)
{
var tmp = sda.options[j].text;
var tmp1 = sda.options[j].value;
sda.remove(j);
j--;
var y=document.createElement('option');
y.text=tmp;
try
{sda1.add(y,null);
}
catch(ex)
{
sda1.add(y);
}
}
}
}

function moveinid()
{
var sda = document.getElementById('available_services');
var sda1 = document.getElementById('assigned_services');
var len = sda1.length;
for(var j=0; j<len; j++)
{
if(sda1[j].selected)
{
var tmp = sda1.options[j].text;
var tmp1 = sda1.options[j].value;
sda1.remove(j);
j--;
var y=document.createElement('option');
y.text=tmp;
try
{
sda.add(y,null);
}
catch(ex){
sda.add(y);
}

}
}
}




</script>
{/literal}
<center>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=60% valign=top>
<form name=fr1 action="?mode=createormodifyrole" method=post onsubmit="selectAllOptions('assigned_services');">
<input type=hidden name=flag value=e>
<br><br>
<center>
<table width="70%" cellpadding=8 cellspacing=0 class=bord>
<tr>
<th colspan=3>
{$msg}
</th>
</tr>
<tr>
<td><b>ROLE</td>
<td><select name="role_id">
<option value="--">--Select--</option>
{html_options options=$all_roles selected=$role_id}
</select></td>

</tr>
<tr>
<td><b>Available Services</td>
<td></td>
<td><b>Assigned Services</td>
</tr>
<tr>
<td>
<select size="6" id="available_services" name="available_services[]" rows=3 multiple>
{html_options options=$all_services selected=$service_id}
</select>
</td>
<td align="center" valign="middle">
<input type=button value="ADD" onclick="moveoutid()"></br>
<br>
<input type=button value="REMOVE" onclick="moveinid()" >
</td>
<td>
<select size="6" id="assigned_services" name="assigned_services[]" rows=3 multiple>

</select>
</td>
</tr>
<table>
<tr>
<td align=center colspan=2><input type=submit value="&nbsp;Submit&nbsp;">
</table>
</table>
{php} include "footer.php"; {/php}[/PHP]

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Nov 14 '08

re: how to get the value of selected option in this code


Heya, vraamu.

Try removing the space character between 'value' and '='.

E.g.,
Expand|Select|Wrap|Line Numbers
  1. <option value="0">Admin</option>
  2.  
  3. <!-- instead of: -->
  4. <option value ="0">Admin</option>
  5.  
Reply