Using PHP to dynamically create select tag fails - Mozilla

This is a discussion on Using PHP to dynamically create select tag fails - Mozilla ; I am using PHP to dynamically create an html select tag. The select tag will have one of the option tags with the selected="selected" attribute added by the PHP code. I have a separate select tag that is hardcoded html, ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Using PHP to dynamically create select tag fails

  1. Using PHP to dynamically create select tag fails

    I am using PHP to dynamically create an html select tag. The select
    tag will have one of the option tags with the selected="selected"
    attribute added by the PHP code. I have a separate select tag that is
    hardcoded html, which also has the selected="selected" attribute added
    to one of the option tags. When I save the code and refresh the
    screen, both dropdowns contain all of the option values, but neither
    of them have the proper default value selected (where the
    selected="select" attribute is).

    When I view the source code, the select tag looks exactly as it
    should, but the default option is not being selected. For example, the
    screen code generated looks like:


    ....The INFJ should be the value shown, but instead, it is ENJF.

    The even stranger thing is that the select tag that was hardcoded ALSO
    fails to display the selected value and instead displays the first
    option in the list.

    If I remove the php code, the hardcoded select tag works as it should.

    I thought it was a PHP issue, but it works just fine in IE8, I'm sorry
    to say.

    So, please tell me if there is a workaround for this.

    Thank you.

    Tim

    Firefox version: 3.5.2 (.NET CLR 3.5.30729) Operating system: Windows
    XP

  2. Re: Using PHP to dynamically create select tag fails

    Thanks for your response, Andrew. I did strip the source code down to
    the minimum as shown below. Interestingly enough, the first time I
    displayed the file in firefox, it did show the right selection
    (INFJ). But, if I selected a different item and then clicked the
    refresh button, that new item displayed and not the one that the PHP
    selected. However, the source code (shown below), as I mentioned in
    the original posting does have the item the I wanted to see selected
    with the selected attribute. So, I don't know if you did that with
    your code...trying to select another and then refreshing the screen,
    but it doesn't work for me in FF (it still works in IE). I was also
    wondering...shouldn't your test file be a .php file?

    This seems so basic, so I'm sure I'm missing something obvious and I
    appreciate your attempt to help.


    Tim

    Below is the source PHP code and then after that is the source copied
    from the browser:




    Test


    Type:



    mysql_close();
    ?>




    BROWSER SOURCE:




    Test


    Type:









    On Aug 27, 7:07 pm, Andrew DeFaria wrote:
    > This is probably not the right group to ask this question in...
    > dunerunner wrote:
    >
    > I am using PHP to dynamically create an html select tag. The select tag will have one of the option tags with the selected="selected" attribute added by the PHP code. I have a separate select tag that is hardcoded html, which also has the selected="selected" attribute added to one of the option tags. When I save the code and refresh the screen, both dropdowns containall of the option values, but neither
    > of them have the proper default value selected (where the selected="select" attribute is).
    > When I view the source code, the select tag looks exactly as it should, but the default option is not being selected. For example, the screen code generated looks like:
    > This works as expected for me (http://defaria.com/test.html)....The INFJ should be the value shown, but instead, it is ENJF.I see INFJ in my example.The even stranger thing is that the select tag that was hardcodedALSO fails to display the selected value and instead displays the first option in the list.As you can see athttp://defaria.com/test.html- my hardcoded example works. Yours above is an excerpt of a larger HTML file so there'sprobably something else going on with that. If you pair it down to the bare essentials (like mine) does it work for you?If I remove the php code, thehardcoded select tag works as it should.Still further evidence that something in your larger HTML file is in error. You could, for example, be missing some closing tag.I thought it was a PHP issue, but it works just fine in IE8, I'm sorry to say.IE 8 may be forgiving of that (shouldn't be but are you in "quirks mode" of IE 8?) but FF isn't. Have you tried a validator?So, please tell me if there is a workaround for this.Let's first make sure the code's valid...Thank you.
    > Tim
    > Firefox version: 3.5.2 (.NET CLR 3.5.30729) Operating system: Windows XPWhat do you think .NET has to do with FF?
    > --Andrew DeFariaYes, I guess, they oughtta name a drink after you. - JohnPrine



+ Reply to Thread