Hello members
I am working with PHP(4.3), mysql(3.23.54) and Apache 1.3.27 on Windows 2000 server. I want the following thing to happen. If a user select an option from a combobox then some other elements on the form will be filled up by the values from database. If JavaScript can perform this please give me some tips about that.
click event on combo box
Moderator: General Moderators
<select>-elements expose a onChange-event that can be used to trigger a function, e.g.But note that php and javascript have (virtually) nothing to do with each other. You cannot call a php-function that resides server-side from the client-side browser/script.
Code: Select all
<html>
<head>
<script type="text/javascript">
function changed()
{
alert( document.getElementById("sel").value );
return true;
}
</script>
</head>
<body>
<select id="sel" onChange="changed()">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</body></html>click event on combo box
Dear volka
Thank you very much for your kind reply. Would you please suggest me what shold I do to achieve my objective? Waiting for your response.
Thanks again.
Thank you very much for your kind reply. Would you please suggest me what shold I do to achieve my objective? Waiting for your response.
Thanks again.
if you really need to pull the data from a database when users change settings you might use frames. In the onChange-function you'd change the url of the next frame.
As a simple example:
As a simple example:
Code: Select all
<!-- file: test.html -->
<html>
<frameset cols="20%,*">
<frame name="first" src="test.php" />
<frame name="second" src="test.php?option=1" />
</frameset>
</html>Code: Select all
<html><?php // file: test.php
if (isset($_GET['option']))
echo '<body>', $_GET['option'];
else
{ ?>
<head>
<script type="text/javascript">
function toggle(elem)
{
parent.second.location = "<?php echo $_SERVER['PHP_SELF']; ?>?option="+elem.value;
}
</script>
</head>
<body>
<select onChange="toggle(this)>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<?php
}
?></body></html>That's of course an option, but I gave up to explain that since I always failed to do so 
but an example can be found at the creative-website
http://uk.europe.creative.com/support/m ... elcome.asp
but an example can be found at the creative-website
http://uk.europe.creative.com/support/m ... elcome.asp
Hello,
Thank you every one. I have done it in the following way:-
<script language="JavaScript">
function getCourseID(c_id)
{
window.location="Course_Offer_Entry.php?id="+c_id
}
</script>
.................................
<select size="1" name="Course_No"
onChange="getCourseID (window.document.Course_Offer.Course_No.options[selectedIndex].text)
Have you any better suggestion to optimize the code?
Thank you every one. I have done it in the following way:-
<script language="JavaScript">
function getCourseID(c_id)
{
window.location="Course_Offer_Entry.php?id="+c_id
}
</script>
.................................
<select size="1" name="Course_No"
onChange="getCourseID (window.document.Course_Offer.Course_No.options[selectedIndex].text)
Have you any better suggestion to optimize the code?