<select name=""> variable from javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jfooobet
Forum Newbie
Posts: 1
Joined: Tue Aug 18, 2009 11:08 am

<select name=""> variable from javascript

Post 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>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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.
stratbeans
Forum Newbie
Posts: 12
Joined: Sat Aug 29, 2009 2:23 am

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

Post 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..
stratbeans
Forum Newbie
Posts: 12
Joined: Sat Aug 29, 2009 2:23 am

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

Post by stratbeans »

??????
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

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

Post 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
Post Reply