开发者

Can i echo hidden field under <select>

开发者 https://www.devze.com 2023-03-08 06:42 出处:网络
I do not know if it makes sense but i am trying to echo a hidden field in select box but does not work. How can i echo

I do not know if it makes sense but i am trying to echo a hidden field in select box but does not work. How can i echo

echo "<input name='testt' type='hidden' id='testt' value='".$ver["cats_fee"]."'>";

in here:

<select size="1" name="parentcat">
    <option value='0'>---- Top Category ----</option>
    <?
开发者_如何学运维    $al=mysql_query("select * from cats where cats_parentid='0' order by cats_id desc");
    while($ver=mysql_fetch_array($al))
    {

        echo "<option value='".$ver["cats_id"]."'>".$ver["cats_name"]."</option>";
                $al2=mysql_query("select * from cats where cats_parentid='".$ver["cats_id"]."' order by cats_id desc");

        while($ver2=mysql_fetch_array($al2))
        {
            echo "<option value='".$ver2["cats_id"]."'>&nbsp;&nbsp;&nbsp;&nbsp;> ".$ver2["cats_name"]."</option>";

        }
    }

    ?>
</select>


It looks like you're trying to send multiple pieces of data based on a user-selection. It's easier just to send the unique id (as you are already doing) then lookup the 'fee', along with any other data you need' in the script that the form sends to.

As an aside, it also looks like you are making many database calls to, effectively, get all cats back. If that's true, it's probably more efficient to just get them all with a single call and handle the hierarchy in your script.


Because both the select box, ancd an input field are form elements, you can't nest them. But because you only use hidden input fields for storing data on your page, out of sight for the user, it doesn't really matter where you place it, as long as it's inside the form.


You can't see which option the user is selecting on the client side when you are at the server side. The solution is using javascript - which is a client side language, search like this or this would help alot I think.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号