We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,619 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to pick values from the list box using php?

Hi,

[B]while($row = mysql_fetch_array($result))
$rows[] = $row['crseid'];
print "<td>";
print "<select name='ccrseid'>";
foreach($rows as $row)
{ 
     echo "<option value='$row' selected>$row</option>";

}
print "</select>";
print "</td>";
[/B]

Always, i am getting the last values. I can't retrieve the remaining values. Without $_POST[] ARRAY,how i can print the select option values without by clicking "submit" button and once by changing the select option values, and the values in the text box should gets changed. Thanks in advance

4
Contributors
10
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
11
Views
jacksantho
Junior Poster
169 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 0
"<select name='ccrseid' MULIPLE SIZE=10>";

If you want to do things without submitting, then you must use javascript to do so.

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

hi,
"<select name='ccrseid' MULIPLE SIZE=10>";

why should use MULIPLE SIZE=10..? what is the meaning?

jacksantho
Junior Poster
169 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 0

Below is JavaScript for submitting form on change of drop-down.

print "<select name='ccrseid' onchange='document.getElementById(\'formId\').submit();'>";

Where formId is the id of form tag.

vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

I can't retrieve the remaining values.

After form submission You can only get one value that user have selected.
Why do you want all values in drop down?

vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

why should use MULIPLE SIZE=10..? what is the meaning?

I guess If you want allow user to select multiple items. It will show 10 items in one screen.

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

Hi,
I dont need all the values from select option. When i am selecting some values from drop down box...i need only that value which am i choosing.


print "<select name='ccrseid' onchange='document.getElementById(\'formId\').submit();'>";

Above one is that javascript code. What is the purpose to add the above one?

jacksantho
Junior Poster
169 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 0

That line was for submitting form without button click.
BTW here is one demo code which may help you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script language="javascript">
function showMe(str)
{
	document.getElementById('myDiv').innerHTML = ' You have selected : '+str;
}
</script>
<select name="ccrseid" onchange="showMe(this.value);">
<option value="">Select</option>
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
<option value="Four">Four</option>
</select>
<div id="myDiv"></div>
</body>
</html>
vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

Hi,
I got it what i expected. But, how can i print "str" values inside PHP tags. "str" value is inside in javascript...how can i print this values inside PHP tags anywhere. THANKS

jacksantho
Junior Poster
169 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
Skill Endorsements: 0

Hi,

I have modified the code of vibhadevit for you. hope this helps.

<?php
$link = mysql_connect('localhost','palak','palak');
$seldb = mysql_select_db('apalgujarati',$link);

$getuserqry = mysql_query("select id,name from apal_user");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script language="javascript">
function showMe(str)
{
	document.getElementById('myDiv').innerHTML = ' You have selected : '+str;
}
</script>
<select name="ccrseid" onchange="showMe(this.value);">
<option value="">Select</option>
<?php
while($getuserrow = mysql_fetch_array($getuserqry))
{
?>
<option value="<?php echo $getuserrow['name']; ?>"><?php echo $getuserrow['name']; ?></option>
<?php } ?>
</select>
<div id="myDiv"></div>
</body>
</html>

This will fetch all of your data from the db and also display the selected name.

Hope this will work for you. :)

pbcomput
Junior Poster in Training
59 posts since Feb 2010
Reputation Points: 19
Solved Threads: 4
Skill Endorsements: 0

str variable is in JavaScript. It is client side language.
While PHP is server side language.
Can you post your reason for passing str value to php tag with example.

vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1099 seconds using 2.67MB