Hey everyone!

After some research I have found that I need some javescript help to process a users click from a html drop down select list..

I am trying to create an admin area for a website in php and using mysql database.

In my admin home page, I have an option to choose a title on a page, from a dropdown select list. Which when clicked/chosen, should redirect to the edit_page.php..

My question is: When the admin have clicked a value from the select box, how do I redirect to the edit_page.php, where there is a form with the following fields:

- Page full title: Form here
- Linklabel: Form here
- Heading: Form here
- Body text: Form here

And I want to prepopulate the form fields so its easy to seee what to edit.

But I basically dont have any idea on how to get the data put into the form fields in edit_page.php.. I am new to PHP :-)

My code for the select dropdown is:

$query="SELECT id, linklabel FROM pages ORDER BY id ASC";

/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
'<form action=edit_page.php method=post>';
$result = mysqli_query ($myConnection, $query);
echo "<select class=\"boxstyles\" name='linklabel'>Choose a page to edit</option>";
// printing the list box select command

while($nt=mysqli_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[linklabel]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box 
'</form>';
mysqli_free_result($result);
?>

In the database there is more than these two fields: ID, LINKLABEL - There is also: PAGETITLE, HEADING and BODYTEXT.

To prepopulate the edit_page.php form fields, do i need to include more than the: ID and LINKLABEL in the select box.
I hope this makes sence, and cleares my problem..

Recommended Answers

All 3 Replies

Klemme,

As far as I can see, you just need to know how to submit the form you have created.

This is done with a submit button :

<form action="edit_page.php" method="post">
  <select class="boxstyles" name="linklabel">
    <option>Choose a page to edit</option>
    <option value="linklabel_1">Title 1</option>
    <option value="linklabel_2">Title 2</option>
    <option value="linklabel_3">Title 3</option>
  </select>
  <input type="submit" value="Go" />
</form>

No javascript is necessary.

The rest is a matter of writing edit_page.php, which is a question for the php forum.

Airshow

Hi Airshow,

Thanks for your answer! And thanks for correcting my missing <option> tag too.. :-)

I was thinking it would be smart if the option value, could work as a link, just when it was clicked, without a submit button?

Reconsidering it, I think it might be better with a submit button, also it can be made with nice graphichs etc.

But I meant if the option value could work as a link, without a submit button, by adding some kind of onclick event..?

If its a longer script, and too complicated, I might go with the submit button :-)

Again thanks for the reply!,

Klemme

Klemme,

Yes you can make submission happen automatically when an option is selected.

Put this in the document head (inside script tags)

onload = function() {
  var selectMenu = document.myForm.linklabel;//where myForm is the form's name
  selectMenu.onchange = function() { this.form.submit(); }
}

It's best also to include a submit button, for rare users with JavaScript turned off.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.