By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,935 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,935 IT Pros & Developers. It's quick & easy.

How can i grab the id value using jQuery?

P: 69
To explain i think I might be easier to show my code first...

My HTML is a form so someone can write and send a message. they can send the message to any name in my database.

Expand|Select|Wrap|Line Numbers
  1. <form method="post" name="postMessage" action="">
  2.  
  3. <textarea class="input" cols="50" rows="10"></textarea>
  4.  
  5. <input type="hidden" name="there_id" id="page_idmessage" value="" /> 
  6.  
  7. <label for="search">Send To:</label>
  8.  
  9.  
This code is straight after...

As the user types in the input text box, the names from the database all apear in a dropdown-box type list. These names appear between the <div id="displaySend">

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <div id="searchBar">
  4.     <input type="text" class="searchMessageSend" id="searchbox" /><br />
  5.  
  6. <div id="displaysend">
  7.  
  8.  
  9.               </div>
  10.            </div>   
  11.         </div>
  12.  
  13.  
  14.  
  15.  
The code generated bettween the <div id="displaySend">

looks like this....

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div style="position:relative;z-index:100000;">
  3.  
  4. <a href="#" class="click" id="24">
  5.  
  6. <div class="display_box" id="display_boxSearch"> 
  7.  
  8. <p id="searchName">Luke</p>
  9.  
  10. </div>
  11.  
  12. </a>
  13.  
  14. </div>
  15.  
  16.  
I would like to click the <a class="click" id="24">

And on-click pass the id value ( 24 ) into the value on this input field....

<input type="hidden" name="there_id" id="page_idmessage" value="" />

And also pass the name ( luke ) into the actual input box...

<input type="text" class="searchMessageSend" id="searchbox" />

I have tryed for ages and the best jQuery i could come up with is below, but doesn't seem to work :( ....

Expand|Select|Wrap|Line Numbers
  1.  
  2. $(document).ready(function(){      
  3.  
  4.      $("a.click").click(function() {      
  5.  
  6.      var  Id = $(this).attr("id");
  7.      var  name = $(this).children(text);
  8.  
  9.      $("#page_idmessage").val(Id);
  10.      $("#searchbox").val(name);
  11.  
  12.  
  13.  
  14.      });    
  15.  
  16. });    
  17.  
  18.  
please help.
Mar 6 '12 #1

✓ answered by acoder

Any error messages?

PS. the ID should not be numerical.

Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Any error messages?

PS. the ID should not be numerical.
Mar 17 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.