hi guys,

i have a form echoed in php, and am trying to using the onChange function in an option box to submit values returned by a drop down box (when a user clicks on an option in a drop down).

echo "<SELECT NAME=\"m\" onChange=\"submit()\">";
echo "<option>IPTIS Ticket Name</option>";

echo "<OPTION VALUE=\"$field_name\">$ticket_name</OPTION>";

$field_name and $ticket_name are just stuff retrieved from the database which works fine.

The trouble is the form submits but wont return the results as a submit button i have does.

    ive also tried using an action =correct stuff to do here

    thing but that doesnt work either.

    and also tried putting it in the form tag

      Try using this.form.submit() instead of just submit(). (No guarantees, though -- JS is not my strong suit.)

        NogDog is correct. As your code is currently written, you're trying to call to a user-defined function named submit(); if no such function is defined, you'll just get an error. You need to invoke the built-in submit() method of the <form> object in which the <select> resides, which is something different.

        The reserved keyword "this" refers to the current object (in this case, your <select> control). The form property of a control (such as your <select>) refers to its parent <form>. The submit() method of the form—you guessed it—submits the form. Hence, this.form.submit() means "find the form to which I belong, and trigger its submit() method".

        When debugging JavaScript, I suggest using a browser (such as Firefox) that has a good JavaScript error console, so you can see exactly what is going wrong. (In this case, it'd tell you that you're trying to call an object that doesn't exist.) It'll add years to your life. You may also want to bookmark this site and this site; they're excellent references for information on JavaScript and the DOM.

        Also, since you're new here: questions about HTML, CSS, and JavaScript belong in the "Client-Side Technologies" forum, not the PHP forums. No biggie...just letting you know.

          Write a Reply...