I’m working on a WordPress site. As far as I can tell, it doesn’t really have any XML which I see several tutorials reference. So, what I would like to know is how to select an HTML element by its id and then echo the result without referencing any XML. Thank you.
Thanks for responding. Below, you should see a screenshot that I included. I’m on a dual screen setup for work, so I made it a point to make the inspector view of the elements super large.
In the screenshot, you’ll notice that the select box is highlighted and it has an id. What I’m seeing help with is, for example, selecting that select box with PHP exclusively. Let me know if there’s something else I need to clarify. Thank you.
It’s still not clear what your intention is.
It is possible for PHP to read an HTML document and pick elements within it based on things like ID and other attributes.
But what do you expect to do with the element once selected?
The above is about reading HTML which has already been written. Unlike JS, PHP can’t alter what’s already written, not without re-writing it.
Good to know. I wasn’t aware of that. So, this is what I’m trying to do. Certain products might have a certain option of a select field disabled. If the PHP function is targeting that option to be disabled, when a user selects it, the option will be reset to “Select an option…”
As I said, PHP can’t change what is already written, but it is the usual job of PHP to write the HTML to the page in the first place. So when it is doing that it can write it any way you choose.
When PHP is populating a list of options in a select input, if one option should be disabled, you can add the disabled attribute when you initially write it to the page.
So it may be that this is something you should be doing using js.
The other Sam has already explained things well but perhaps a little clarification will help.
The way that PHP works is that the compiler reads the PHP file from beginning to end. It generally writes the HTML out as-is and processes the PHP code when it is encountered. Whatever HTML is generated by the PHP code is written and the compiler proceeds from there. It is not clear what you need to do but you just need to figure out a different design depending on what you need to do.