I tried this, but it didn't work.  I need the value inside the form still
because the value of the select will be written to an array that gets passed
to the next page (as hidden inputs), which will in turn be compiled into a
value list for a db query.  I tried making the name of  the select be the
array posistion (value[7] in this case), but when I changed values, IE
errored and said that value.7 isn't an object.  If I don't change the
option, ie, I use the default select value, the code works.  But as soon as
I change the option, IE gives me an error and can't change the value.  Would
this work: make the onChange event trigger a page refresh to set the form
values?  Or will that simply draw the page again?  Thanks.

Here is the code I'm using...all of the php variables have values that work,
the problem is in changing the value of the select
-----BEGIN--------
<script>
<!--
function changeValue(newValue) {
document.addstuff.value[7].value = newValue;
}
file://-->
</script>

echo "<td colspan=\"$numfields\"> Select which location you want this to
apply to.<br><select name=\"pickloc\"
onChange=\"changeValue(this.options[this.selectedIndex].value);\">";

 $i=0;

 while ($locidval = mysql_fetch_object($locinfo)){
      echo "<option value=\"$locidval->LocationID\">Location:
$locidval->Area</option><br>\n";
 }//end while

 echo "</td></select><input type=\"hidden\"
name=\"value[$locidnum]\"></tr><tr>\n";

------END-----------


> just write a js function like:
>
> --cut here--
>
> <script>
> <!--
> function changeValue(newValue) {
> document.formname.inputNameToChange.value = newValue;
>
> file://here is alert to show you the thingy
> alert(document.formname.inputNameToChange.value);
> }
> file://-->
> </script>
>
> <form name=formname>
> <input type=hidden name=inputNameToChange>
> <select onChange="changeValue(this.options[this.selectedIndex].value);">
> <option value=value1>label1
> <option value=value2>label2
> </select>
> </form>
>
> --end cutting--
>
> DanO (javascript is your friend, not your enemy!)
>
>
> -----Original Message-----
> From: Jason Jacobs [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 18, 2001 1:33 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] question (as if anything else would be in an email to the
> list...)
>
>
> Hi again.  I have a new problem.  I have a form with a drop down list.
When
> the user chooses something from the list, I need a variable to change
values
> so it can be used upon submission of the form.  I thought maybe I could
> throw a little line of code into an onChange() function in the <select  >
> tag, but I got the MS Debugger thrown up on me.  Anyone got an idea of how
> to do this?  Is it possible to call a javascript function and change the
> variable in there?  Or an easier way (like inline php code...)?  Thanks
>
> Jason


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to