943,991 Members | Top Members by Rank

Ad:
Nov 2nd, 2006
0

Submit or action button

Expand Post »
Hello

I have a web page which has a drop down menu.
I want the user to select an option from the drop down menu, then click submit.

This will then activate my php script and select data from my MYSQL database and populate the fields.

How do i action a button, so when i click, it activates a peice of html / php code?
Similar Threads
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
sgriffiths is offline Offline
61 posts
since Jun 2006
Nov 2nd, 2006
0

Re: Submit or action button

use onChange event.
Reputation Points: 85
Solved Threads: 42
Nearly a Posting Virtuoso
vishesh is offline Offline
1,362 posts
since Oct 2006
Nov 2nd, 2006
0

Re: Submit or action button

Client vs. Server. The only thing that will "activate" PHP code is a server request. There are two types of server request, GET, and POST. GET requests happen by typing in a URL or clicking a link. POST requests happen when you submit a form.

As far as "activating" HTML code... that happens when the browser renders a page. I think you mean JavaScript code, and there are lots of ways to run JavaScript. Every HTML element has associated JavaScript events and event handlers. You, as a developer, have to code them.

The thread title seems to indicate you want to know the difference between a submit button and a regular button, but you don't ask that in your post. You're going to have to narrow things down to a specific question. Which piece of the puzzle can you not do?

1. Write an HTML form with a dropdown list and a submit button?
2. Write a PHP program to process the form results?
3. Query a MySQL database?
4. Process the query results and output new HTML?
Last edited by tgreer; Nov 3rd, 2006 at 10:52 am. Reason: Fixed typo/grammar.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Nov 3rd, 2006
0

Re: Submit or action button

ok ok

What i wanted was an onChange option, this then calls a javascript procedure

But i need the procedure to be php with embedded html
Reputation Points: 9
Solved Threads: 0
Junior Poster in Training
sgriffiths is offline Offline
61 posts
since Jun 2006
Nov 3rd, 2006
0

Re: Submit or action button

Re-read my post. PHP is server-side code. JavaScript is client-side code. You cannot write PHP that will run on the client in response to a JavaScript onChange event. I don't know what "embedded HTML" means in this context, sorry.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Nov 6th, 2006
0

Re: Submit or action button

Click to Expand / Collapse  Quote originally posted by sgriffiths ...
ok ok

What i wanted was an onChange option, this then calls a javascript procedure

But i need the procedure to be php with embedded html
Like mentioned, JavaScript is client side (runs on the browser) and PHP is server side (runs on the server).

Regarding: "php with embedded html".
I believe you mean PHP embeded in HTML. This is a confusing statement that "sells" PHP when you are new to the language. It doesn't mean that PHP is embedded in HTML some how literally speaking. All php is processed on the server and only HTML is sent to the browser. It just means that you can seperate PHP in <?PHP ?> tags and place this in between your HTML.

So in order to use PHP, you'll have to make a request to the server, as mentioned with a form POST, or a GET request.

This equates to a new page load on the browser. Or a refreshing of a hidden Iframe or use of AJAX if you dont want to reload the page.

I believe what you want is simple a new page load, as that is the simplest and most conventional.

If you want to make a GET request using JavaScript, you can use:

window.location = 'http://example.com';

If you need to submit a form automatically, use form.submit(); where "form" is the form object defined in the DOM.

Exaple:
make a HTTP GET on selecting a new option.

[HTML]<select name="selectbox" id="selectbox">
<option value="">Select a Page</option>
<option value="http://example.com/page1.php">Page 1</option>
<option value="http://example.com/page2.php">Page 2</option>
</select>

<script type="text/javascript">


var select = document.getElementById('selectbox');
select.onchange = function() {
window.location = select.options[select.selectedIndex].value;
}

</script>[/HTML]
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: help with this hiding text example Javascript
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Scrollbar position on refresh problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC