Mayeenul Islam
Mayeenul Islam

Reputation: 4772

How to load database content using Select box without button & javaScript

I'm making an administrative page for a website, for editing front-end contents. I don't want to use JavaScript, I want to make it with raw PHP.

The thing is: The user will choose a page from the select box, and the contents according to the page will be loaded into two text boxes. Then the user will edit them on text boxes and update the contents using an update button.

(there is no submit button for the select box, I want 'onselect' data content load)

I need, the user will simply select a page, no button to be pressed then and the content will be loaded. I want not to deploy JavaScript for this. Is it possible using raw PHP? Any suggestion?

Upvotes: 0

Views: 486

Answers (3)

maja
maja

Reputation: 18064

Yes, it's possible with raw PHP, but I do not recommend it.

You can put the select-box inside a

<form action="targetFile.php" method="GET">

To submit the form without a submit-button, you can use:

<select name="sel" onChange="this.form.submit()">

When the form is submitted, the browser loads the site "targetFile.php" On this site, you can use php to set the text-box content:

<input type="text" value="
    <?php
        if($_GET['sel'] == 0) echo "content1";
        else echo "content2";
    ?>
">

If you want to load the content dynamically (without realoading a site) you have to use Javascript and maybe Ajax.

Upvotes: -1

Johanna Larsson
Johanna Larsson

Reputation: 10761

PHP is a server side programming language. You can't really affect the client side directly, only indirectly through forms etc.

Upvotes: 1

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382394

If you accept your users may have to use the enter key, which will submit the form, you're fine.

But you can't have an action occurring on a select, without even using the enter key, without javascript.

Note that the requirement to not use javascript, especially for an administrative tool, doesn't make sense.

Upvotes: 1

Related Questions