Page 1 of 1

<select name=""> variable from javascript

Posted: Fri Aug 21, 2009 1:23 pm
by jfooobet
I have a table where i add rows with a javascript and each row contains this code for a select form.

But i need each "<select name=" to be unique. So how can i insert a variable from the javascript into this tag? Or is there other ways?

Code: Select all

 
<td id="spiller">
        <?php
            $data = mysql_query("SELECT * FROM _spiller")
            or die(mysql_error());
            echo "<select name=spiller>";
            while($info = mysql_fetch_array( $data ))
            {
            print "<option value=".$info['spiller'] . ">".$info['spiller'] . "</option>";
            }
            print "</select>";
        ?>
    </td>
 

Re: <select name=""> variable from javascript

Posted: Sat Aug 22, 2009 6:18 am
by jackpf
I obviously don't know how you're processing this form, since you haven't explained, but it sounds like you should be using an array for these select boxes.

If you append the select name with [], PHP will put them all into an array for you.

Re: <select name=""> variable from javascript

Posted: Sat Sep 05, 2009 2:44 am
by stratbeans
Hi jooobet,
As per your problem I am concern, you need a global counter that’s it.
Steps to do :
• Create one global variable in php,
• Add this let’s say $counter to <select name=”spiller{$counter}”> ,
• Now increment this counter at every end of select .
That’s it …
Hope this will work for you..

Re: <select name=""> variable from javascript

Posted: Sat Sep 05, 2009 3:08 am
by stratbeans
??????

Re: <select name=""> variable from javascript

Posted: Sat Sep 05, 2009 7:03 am
by jackpf
Wouldn't worry about it - some people just post threads for the sake of it and never check up on them.

You must take it in your stride :P