Jump to content

Problem with keeping the selected value of a drop down menu


notat

Recommended Posts

Hi. I have a project and it's about lessons and students selecting lessons and so on.Each lesson consists of units and each unit of topics. My problem is at the form I have for the creation of each unit. What I want is, when the user is at this form, the first field should be all the lessons that appear through a drop-down menu. The code of the lessons is a string of 2 chars. When the user selects a lesson through the command <select>..<option>, then the next field which is the code of the unit, first it should show the code of the selected lesson and then the user could give an auto-increment number for each code of the unit for the same lesson. The problem is at the <select> command, how to keep the code of the selected lesson, how then the page to refresh so as at the next field to show the code. I have tried Javascript from similar examples from the Internet but nothing seems to work in my case. The code I attach is not right at all, because it shows the code of the lesson only after a lesson is selected and the form is submitted. The logic is not right but it's a test I tried to see what results appear. I hope someone can help me with the code. Thanks in advance,

notat.

 
<?php 
include "db_prog.php"; 
$con=db_connect(); 
?> 
<html> 
<FORM name="theForm" action="<?php echo "$_SERVER[php_SELF]"; ?>" method="POST"> 
<table width=100% border=0> 
<tr> 
<TD align="justify" width=50><FONT face="Verdana" size=-1><B>Lesson title:</B></FONT> 
</TD> 
<td> <select name="name1"> 
<option value="null"></option> 
<?php 
$sql="SELECT code_math,name_math FROM lesson ORDER BY name_math ASC"; 
$res=mysql_db_query($db_name,$sql); 
$num=mysql_num_rows($res); 

if ($num >= 0) 
{ 
while ($row=mysql_fetch_array($res)) 
{ 
echo("<option value=\"$row[name_math]\""); 
$name1=$_POST['name1']; 

if ($row[name_math] == $name1) 
{ 
echo("SELECTED"); 
} 
echo(">".$row[name_math].""); 
} 
} 
?> 
</select> </td></tr> 
<?php 

if ($name1 != null) 
{ 
$sql1="SELECT code_math,name_math FROM lesson where name_math='".$name1 . "'"; 
$res1=mysql_db_query($db_name,$sql1) or die(mysql_error()); 
$row1=mysql_fetch_array($res1); 
$code= $row1[codikos_math]; 
} 
?> 
<tr> <td align="justify" width=50> 
<font size="-1"><b>Unit code: </b></font> 
</td> <td> 
<?php 
echo('<input type="text" size="5" name="code_u" value="' . $code . '">'); 
?> 
<input type="text" size="2" name="code" > 
</td> </tr> 

</FORM> </BODY> </HTML>

Link to comment
Share on other sites

if what your wanting to do is keep the value of the selected option in the list, send the value upon submission using GET

 

<option<?php if ($get['lesson'] == "whatever") { print " selected=\"selected\"";} ?>> lesson</option>

 

if the get variable is present it just sets the option feild be be autoselected on load, hope that helps

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.