Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-20-2011, 11:44 AM   PM User | #1
dk4210
New Coder

 
Join Date: Nov 2002
Posts: 99
Thanks: 13
Thanked 0 Times in 0 Posts
dk4210 is an unknown quantity at this point
Trying to pass a php id to javascript on the same page

Hello Guys,

I need some help here..

I have a page that has a grid on it and I have a hidden div(below the grid). When the link is clicked inside the grid it opens the hidden div using the following code for the link in the grid.

Here is my code with the PHP id that I need to pass

PHP Code:
foreach($ct->data as $key => $value){
   
$ct->data[$key][3]='<a href=#" onclick="part2('.$ct->data[$key][0].');" href="javascript:void();">'.$ct->data[$key][3].'</a>'
Here is the code in my head
Code:
<script type="text/javascript">
function part2(id) {
var part2 = document.getElementById('part2');
   if ( part2.className == 'hidden' ) {
      part2.className = 'visible';
      document.getElementById('message').InnerHTML = 'This is the ID: '+id
   } else {
      part2.className = 'hidden';
   }
}
</script>
Added this to my hidden div to show the id
Code:
<span id=message></span>
Any help would be appreciated..

Thanks, Dan
dk4210 is offline   Reply With Quote
Old 07-20-2011, 12:51 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
It's innerHTML and not InnerHTML ... Javascript is case sensitive
devnull69 is offline   Reply With Quote
Old 07-20-2011, 01:19 PM   PM User | #3
dk4210
New Coder

 
Join Date: Nov 2002
Posts: 99
Thanks: 13
Thanked 0 Times in 0 Posts
dk4210 is an unknown quantity at this point
Hey that done it.. Thanks so much for you help..

One more question.. How can I grab that id and add it back as a php id?

in the layer?

currently it displays because of this - <span id=message></span>

I want it to be passed to PHP

Like this

$id

Any ideas?
dk4210 is offline   Reply With Quote
Old 07-20-2011, 07:04 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
I don't get that ... what should be the result of such an action? You need to understand that PHP already finished(!) running when javascript runs. So you can not pass variables to PHP just like that.

The only thing you could do is start a new request to a PHP, either through browser redirect or an Ajax call.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:06 PM.


Advertisement
Log in to turn off these ads.