ed
Member
Registered: 10th Sep 03
User status: Offline
|
I'm doing a website in PHP. I got a drop down menu at the top of a page at the moment that you select an option from to query the MySQL database. BUT to get anything to apear on the page you have to press the submit button as the query works on a form variable. Does anyone know how to get a form to submit automaticaly when a page loads. I think it would use the onLoad = tag in java script but I cant figure anything out! Does anyone on here know anything about this sorta thing??? Thanks for any help ED
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
basically, you want the drop down menu to automatically sumbit when the user selects an options? if so, then its a case of wacking a 'onchange' within the drop down menu tag and put some javascript in it ive forgotten how to do it (just had a play, but cant get it to work) so have a look on google mate, but its something along he lines of 'document.*formname*.submit'
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
I used onChange on a different site somewhere, so i'll have a look it how I did that. Will that submit the form when the page loads though?
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
no that will submit when the user changes the options in the drop down menu
Although if you want the page to submit when the it loads, then wack a 'onLoad; in the body tag, with the submit javascript and that will do it But why the hell you want to submit a page when its loads though the reason you submit data is to get user input (change of data etc).
Best bet mate is to create the whole page in php, so it first loads up the options menu - user selects option (form points to that php page eg: page.php) and it submits. Using flags (data kept in hidden form variables), the php script will know that the user has selected an option, get the data, and then throw out another screen with the selected options menu and the data below it etc and you reset the flag.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
Yea that makes more sense than what I'm trying to do! (My first PHP/MySQL site, so i'm getting a bit confused by it all )
|
Joff
Member
Registered: 17th Oct 00
Location: Cambridgeshire
User status: Offline
|
code:
<form method="post" name="myForm" action="submit.php">
<select name="selOption" onChange="document.myForm.submit();">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</form>
|
Joff
Member
Registered: 17th Oct 00
Location: Cambridgeshire
User status: Offline
|
Oops - just re-read your first post..
code:
<html>
<head><title>Somepage</title></head>
<body onLoad="document.myForm.submit()">
<form method="post" name="myForm" action="submit.php">
<input type="hidden" value="somevalue" name="txtValue">
</form>
</body>
</html>
[Edited on 14-02-2004 by Joff]
|