Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP <select onchange=submit()> does not work! HELP

Status
Not open for further replies.

scriggs

IS-IT--Management
Jun 1, 2004
286
GB
I have a form in PHP which generates the HTML below:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>

<title>Time and Fees Data</title>
<!-- 
Generates a dynamic drop down list of all
client codes in Time & Fees.

When a client is selected the page refreshes
and loads the client details from Time & Fees
-->
<style type="text/css">
<!--
body {font-family:verdana; font-size:11px; font-style:normal; font-weight:normal;}
th {color:white; background-color:gray; font-size:11px;}
td {background-color: silver; font-size:11px;}
-->
</style>

</head>
<body>
<form method="post" action="/php/feesodbc.php">
<select name="custname" onchange="submit()">
<option>ABB01</option>
<option>ABB02</option>
<option>ZZZCHA05</option>
</select>
<input type="submit" name="submit" value="Display Time and Fees Information">
</form>
</table>    

</body>
</html>

If I select a code from the drop down list and then click 'Display time and Fees Information' it works fine. I want it to autorun if someone selects the drop down list. So I added onchange=submit() - why doesn't this work?
 
While it is not a PHP question, since onchange="" invokes a client-side javascript function, the answer is so short I think it is best to give it you.

So, as said, onchange="" will not call a PHP function or anything else. It can call any JavaScript command or function. However, unless you have defined a custom function in JS called submit, your solution will not work. You need to use DOM (Document Object Model) to reference the element and call submit. You can do that by:
Code:
<select name="custname" onchange="[b][blue]this.form.[/blue][/b]submit()">
Next time you should ask questions like this in JavaScript forum.
 
Thanks for the reply. I did not realise this was JS. I submitted to JS forum and the actual issue was that the name submit button shouldn't be called submit but should have a unqiue name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top