0

I have this html part for a dropdown menu:

<form name="navList" onsubmit="return submitForm();">
<select name="subMenu">
<option value> </option>
<option value> CR_ID </option>
<option value> CR_HEADLINE </option>
<option value> CRI_CLOSEDATE </option>
<option value> CRI_ASSIGNEE </option>
</select>

How can I change this into php, using this function?

foreach($array as $key=>$value)
{
$html .= "<option value='$key'>$value</key>";
}
echo "<select name="process">$html</select>";
1
  • 2
    "<option value='$key'>$value</key>" - you open option tag, but then close key; however, I don't see a question here. Commented Jul 12, 2013 at 11:12

3 Answers 3

2

You forget to add escape sequences in your output . Please refer this demonstration:-

$optionArray = array(
            0 => 'CR_ID',1=> 'CR_HEADLINE',
            2 => 'CRI_CLOSEDATE',3 => 'CRI_ASSIGNEE'
            );
foreach($optionArray as $key=>$value)
{
$html .= "<option value='$key'>$value</key>";
}
echo "<select name=\"process\">".$html."</select>";

OR

    echo '<select name="process">'.$html.'</select>';
Sign up to request clarification or add additional context in comments.

Comments

0
echo "<select name=\"process\">".$html."</select>";

You needed to escape your quotes.

Comments

0
<?php

$html ='';
$myArray = array(0 => '',1 => 'CR_ID',2=> 'CR_HEADLINE', 3 => 'CRI_CLOSEDATE',4 => 'CRI_ASSIGNEE');

foreach($myArray as $key=>$value)
{
    $html .= "<option value='$key'>$value</key>";
}

echo "<select name=\"process\">".$html."</select>";

Link - http://codepad.viper-7.com/YpccFw

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.