SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery problem with forms

    Lets start with a little history first. I have database and there is some categories. Each category have properties attached to them. What I need to do is an user interface where one could add properties to category from property list and remove properties from certain category. I am quite a newbie with javascript overall and even more with jQuery but I thought jQuery would be probably the solution to this.

    I tried this http://blog.jeremymartin.name/2008/0...th-jquery.html simple example and thought to test with it for starters. So what I am going to try is to fetch the properties from the database to the box1 and certain categorys properties would be on the right side in box2. Any help is welcome how to edit this piece of script so it would match my needs. Need someone to point the right direction what to do.

    First I tried to just get the selected information from the select2 into $_POST array in php but I encountered immediately a problem. Only the last selected value will go into the $_POST array when submit is pressed. Why is this? Here is the code for the first try out:

    PHP Code:
    <?php
    var_dump
    ($_POST);
    ?>
    Code:
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
    
    <script type="text/javascript">
    $().ready(function() {
    	 $('#add').click(function() {
    	  return !$('#select1 option:selected').remove().appendTo('#select2');
    	 });
    	 $('#remove').click(function() {
    	  return !$('#select2 option:selected').remove().appendTo('#select1');
    	 });
    
    	 $('form').submit(function() {
    		  $('#select2 option').each(function(i) {  
    		   $(this).attr("selected", "selected");  
    		  });  
    	 });  
    
    });
    </script>
    HTML Code:
    <div>
    <form action="test.php" method="POST">
    <select multiple id="select1">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
    <option value="4">Option 4</option>
    </select>
    <a href="#" id="add">add &gt;&gt;</a>
    </div>
    <div>
    <select multiple id="select2" name="test"></select>
    <a href="#" id="remove">&lt;&lt; remove</a>
    <input type="submit" value="post">
    </form>
    </div>

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <form action="test.php" method="POST">
     
     
      <div>  
      <select name="select1[]" multiple="multiple"  id="select1" >  
       <option value="1">Option 1</option>  
       <option value="2">Option 2</option>  
       <option value="3">Option 3</option>  
       <option value="4">Option 4</option>  
      </select>  
      <a href="#" id="add">add &gt;&gt;</a>  
     </div>  
     <div>  
      <select name="select2[]" multiple="multiple" id="select2"></select>  
      <a href="#" id="remove">&lt;&lt; remove</a>  
      <input type="submit" value="post" name="submit">
     </div>  
     
    </form>


Bookmarks

Posting Permissions

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