Results 1 to 10 of 10

Thread: [RESOLVED] save listbox items into mysql table?

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: save listbox items into mysql table?

    Quote Originally Posted by Visual Basic.Net View Post
    Thank's alot bro... I tried your code but it didn't work.
    Well you kinda changed it a bit... This is what I had tested, based on your original code:
    Code:
    <?php
       for ($i=0; $i < count($_POST['mylist']);$i++)
    {
    
         echo $_POST['mylist'][$i];
    echo "<br>";
    }
    
    ?>
    <html>
    <head></head>
    <body>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="myForm">
    <select name="mylist[]" size="5" multiple id="myList">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    
    </select>
    <input type="submit" name="submit" value="submit">
    </form>
    
    </body>
    </html>
    
    <script>
    document.getElementById("myForm").onsubmit = function(){
      var myList = document.getElementById("myList");
      for(i=0;i<myList.length;i++){
        this.myList[i].selected = true;
      }
    }
    </script>
    The way you changed it won't work for a couple of reasons.

    1. var myList = document.getElementById("lstname");

    This won't work because it's looking for an element with id='lstname'. You don't have one.

    2. this.myList[i].selected = true;

    I don't think this will work because the "this" in my context referred to the form element, since the function was bound to its "onsubmit" action. I'm not sure if it's referring to the right thing in yours...

    3. onsubmit='tttt()'

    This is a problem because it's calling the tttt() function, but it's not waiting for it to finish before submitting the form. So tttt() isn't getting to finish its work.

    Fixing it would look like this:
    Code:
    <script>
    function tttt(){
    	var myList = document.getElementById("lstname");
      	for(i=0;i<myList.length;i++){
        	myList[i].selected = true;
      	}
      	return true;
    }
    </script>
    <?php
    	if(isset($_POST['sbbutton'])){
    		foreach ($_POST['lstname'] as &$value) {
        		echo $value."<BR>";
    		}
    	}
    ?>
    <form name='myform' method='POST' onsubmit='return tttt()' action='<?php $_SERVER[PHP_SELF] ?>'>
    <select name='lstname[]' multiple size='8' id="lstname">
    <option>test1</option>
    <option>test2</option>
    </select>	
    <input type='submit' name='sbbutton' value='Submit'>
    </form>

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: save listbox items into mysql table?

    It worked! Thank's alot bro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width