Click to See Complete Forum and Search --> : PHP grab value from combo box


girish_mu
April 17th, 2008, 03:16 AM
Firstly, here is my XML file:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sound.xsl"?>
<sound>
<sample>
<title>sample1</title>
<url>http://www.example.com/sample1.mp3</url>
</sample>
<sample>
<title>sample2</title>
<url>http://www.example.com/sample2.mp3</url>
</sample>
</sound>


My XSLT:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script type="text/javascript">

function Listen()
{
var x;
var width = 500;
var height = 350;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
x=document.forms[0].sel_Sounds.value; //Modify this part
url="Listen.php?ID="+x;
newwin=window.open(url,'Listen', params);
if (window.focus)
{
newwin.focus()
}
return false;
}
</script>
</head>
<body>
<form>
<table border="0" align="center">
<tr>
<td>
<select id="sel_Sounds">
<xsl:for-each select="sound/sample">
<option>
<xsl:attribute name="value"><xsl:value-of select="url"/></xsl:attribute>
<xsl:value-of select="title"/>
</option>
</xsl:for-each>
</select>
</td>
</tr>
<tr align="center">
<td>
<input type="button" value="Listen" onClick="Listen();"/>
</td>
</tr>
</table>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


I need to pass the value of the combo box to the Listen.php file. How do I access that value in the combo box?

PeejAvery
April 17th, 2008, 07:08 AM
Any element that is to be processed by a form must have a name attribute. So give it a name, and then you can access it in the PHP page by using $_GET['element_name'] or $_POST['element_name'].

girish_mu
April 17th, 2008, 07:50 AM
I get the following error:

Notice: Undefined index: sel_Sounds in c:\program files\easyphp1-8\www\test\capture.php on line 10

PeejAvery
April 17th, 2008, 08:05 AM
You haven't mentioned anything about that file before. Undefined index means that you are attempting to access an index within an array that does not exist. Double check your array.

And this has nothing to do with XML.

PeejAvery
April 17th, 2008, 08:06 AM
[ moved ]

girish_mu
April 18th, 2008, 01:08 AM
Can anyone help? Will it work if the XML and XSLT are modified?

PeejAvery
April 18th, 2008, 08:26 AM
How can anyone help if you aren't making any sense, nor posting any code. Did you check for the array index as I already mentioned?

Will it work if the XML and XSLT are modified?
Why would server-side code accessing a drop down change by XML unless you were filling the drop down with the XML?

girish_mu
April 18th, 2008, 12:28 PM
I had tried capturing the data from the combo by submitting the form to a page called capture.php and I used the following piece of code:

$captured_data=$_REQUEST['sel_Sounds'];


And I got the error mentioned in a previous post. Have you tried the XML and XSLT? The combo is being filled with data from the XML file.

girish_mu
April 21st, 2008, 10:41 AM
I have found the error and it's working fine now.