2

Hi I'm new to PHP and Jquery! Please look at the codes first, my question follows.

HTML + PHP code:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;   </button>
    <h4 class="modal-title" id="myModalLabel">Add new Project</h4>
  </div>
  <div class="modal-body">
        <p class="validateTips">Select a Project</p> 
        <div id="start">
            <?php
              foreach($data as $list_proj) {
            ?>
                <a><p class="padd" id="<?php echo 'padd'.$list_proj->mlist_id;?>"><u><?php echo $list_proj->proj_title ?></u></p></a>
                <input type="text" name="hide_id"  id="<?php echo 'hide_id'.$list_proj->mlist_id;?>" class="hide_id" value="<?php echo $list_proj->mlist_id ?>" />
            <?php
                }
            ?>
        </div>

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="button" class="btn btn-primary" id="save">Save changes</button>
  </div>
</div>

The above code creates a list of project titles that comes from the database inside the modal.

JQUERY code:

 <script>
    $(window).load(function() {
        $("#hideito").hide();
        });
    $(document).ready(function(){
    $(".padd").click(function(){
        var value = $("#hide_id1").val();
      $(".hide_nayan").val(value);
         $("#hideito").show();
         $("#myModal").modal("hide" ); 
        });
    });
  </script>

The above code must select the specific list that is clicked. Now my question is, how do I get the specific value from the textboxes created in the modal then pass it to another textbox in the page? I have set their ids with "hide_id" + their respective id from the database, but they share a common class name.

2 Answers 2

1
$(".padd").click(function(){
            var projectTitleValue = $(this).attr('value');
            var textboxValueUnderTitle = $(this).parent().next().attr('value');
            });
    });

This isn't the solution, since it's not very clear what you want ( try to explain a bit better) , but this might get you started. Above is example of how you can get the value of project title, and the value in textbox that comes after it. Hope it helps. :)

Sign up to request clarification or add additional context in comments.

Comments

0

as far as i understand you, something like this should do the job:

change this:

 <a><p class="padd" id="<?php echo 'padd'.$list_proj->mlist_id;?>"><u><?php echo $list_proj->proj_title ?></u></p></a>

<input type="text" name="hide_id"  id="<?php echo 'hide_id'.$list_proj->mlist_id;?>" class="hide_id" value="<?php echo $list_proj->mlist_id ?>" />

to this:

<p class="padd" id="<?php echo 'padd'.$list_proj->mlist_id;?>">
<a><u><?php echo $list_proj->proj_title ?></u></a>
<input type="text" name="hide_id"  id="<?php echo 'hide_id'.$list_proj->mlist_id;?>" class="hide_id" value="<?php echo $list_proj->mlist_id ?>" />
</p>

and now the folloing code should work

<script>
    $(document).ready(function(){
        $(".padd").each(function(){
             $(this).find("a").click(function(e){
                    $(e).preventDefault();
                    $(this).find(".hide_id").each(function(){
                         var value = $(this).val();
                         $(".hide_nayan").each(function(){
                              $(this).val(value);
                         });
                    });
                   $("#hideito").show();
                   //$("#myModal").modal("hide" ); //uncomment if you want it
             });
        });
    });
  </script>

2 Comments

your code seems working fine except that it only passes the first value which is "1", even if I click the second project title
My problem has been solved already but I've tried this code and it's only the opposite from the first one, this time it always get the last value from the list. By the way thanks for your help I appreciate it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.