5 Replies - 1772 Views - Last Post: 23 May 2010 - 01:33 PM

#1 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 12:58 PM

I have 3 divs in a page, and each div contains a submit button. When the submit button is pressed, i want to process a form contained in that particular div and insert the id of the div into a database in which the submit button was there.

So, i want to retrieve the id name of the div and store it in a PHP variable so that i can put it in my sql query. How do i achieve it??

This post has been edited by ptamzz: 23 May 2010 - 01:03 PM

Is This A Good Question/Topic? 0
  • +

Replies To: how to get the id of a div and store it in a php variable

#2 Time2Burn  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 01-February 09

Re: how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 01:01 PM

You would need Ajax for that I think. Pass the name of the DIV (the id) with ajax to the PHP script processing the form, then have that script do whatever it needs to do with the id. Whether you want it to echo out the id or if you want to perform a database command with the id in the sql query.
Was This Post Helpful? 0
  • +
  • -

#3 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

Re: how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 01:08 PM

can u get me to a tutorial of that because i don't much know about ajax.
Was This Post Helpful? 0
  • +
  • -

#4 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 01:11 PM

You could do this with javascript, yes, but I think you're just going about the whole thing the wrong way.
Three forms? Then either have each form contain a hidden field with the id of the div in it (or some other identifier) or just decide which submit button was pressed by looking at its value in PHP.
Was This Post Helpful? 1
  • +
  • -

#5 Time2Burn  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 01-February 09

Re: how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 01:16 PM

You could use jQuery to handle the Ajax functionality. There are a lot of tutorials online for how to use jQuery's Ajax functionality, just google. Though I agree with moopet, could you maybe tell us a bit more about why you need this to work that way? What exactly is the page where the 3 forms are located?
Was This Post Helpful? 0
  • +
  • -

#6 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

Re: how to get the id of a div and store it in a php variable

Posted 23 May 2010 - 01:33 PM

@moopet thanks man, u saved me. actually, i'm calling the same form everywhere, the difference is just the division name. I think i can just get the button name then. It should work.

Thanks again.

i wanted to insert in the database from which div i called that form. from both the 3 divs, i'm calling the same form. Later, i'll be retrieving the information from the database and displaying in the respective div from which the form was called.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1