Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign Div ID using variable?

Status
Not open for further replies.

edcharleslynn

Programmer
Jul 20, 2004
11
GB
Hi, just wondered if anyone knows if it is possible to assign a Div Id to a layer using a variable please. I pass some values to a page which then creates a number of layers based on the variables, but i dont know how to assign a different name to each of them

Thanks very much

Ed
 

How are you creating the layers? Dynamically using server-side code (ASP, PHP, etc), or using document.write, or document.createElement, or something completely different?

As you can see, without the relevant information (or any source), it's hard to give an accurate answer.

Dan
 
Sorry, im new to css & DHTML but have been programming PHP. I have an array set as a php session variable. When moving to my page containing layers i loop through each of elements in the array, and for each one create a new layer:

Code:
foreach($selection as $qnum)
{
?>
		
	<div id="!?" style="border-width: 2px; border-style: solid; border-color: black;"; style="position:absolute; width:450px; height:15px; z-index:2; left: 20px; top: 620px; background-color: #EEEEEE; layer-background-color: #FFFF33; border: 1px none #000000; visibility: visible; top: 90px;">
  <div align="center" class="style2">
  
  
  <?php
  $qquery = "SELECT question, response FROM $surveytable WHERE qnum = '$qnum'";
  $getques = mysql_query($qquery)
  	or die(mysql_error());
  $thischoice = mysql_fetch_array($getques);
  extract($thischoice);
  echo $question." = ".$response;
  ?>
  </div>
</div>
	<?php
}
?>

So the layer is created and the question displayed on it. They need to be draggable though, and as far as i am aware i need to give them unique ID's.

Thanks for the help
 

This is more of a PHP question then, as your unique IDs will need to be generated server-side. I suggest you try the PHP forum:

forum434

Hope this helps,
Dan
 
what do you want to name them you can just name them

$GET['value1'] or POST if thats what you are using or you can set your values as sessions as well on your first page. then depending on certain variables you can assign different ids.
 
I don't speak PHP, but it looks to me that you could do it like this:
Code:
<div id="<?php echo "q".$qnum; ?>" style="...
Did you notice that you've got two [tt]style[/tt] attributes in that <div>? I'm sure some browsers will object to that.

Anyway, once you've got your ids in place, you can move all those styles into a style sheet (I'd be inclined to put a [tt]class[/tt] in as well, you can use it to set the border/background/size information common to all questions and use the id for the positioning properties specific to each one).

-- Chris Hunt
 
Thanks very much, i figured out in the end going about it the way chris suggested, so thanks for all your help on this one. Thanks for the tip on the styles as well!

Ed
 
edcharleslynn: there's nothing quite like a member giving feedback on what works, and it's nice to see a new, active - and obviously polite! - member on the fora.

You might like to know that you can mark valuable threads by awarding a Star. Below each post is a link labelled "Thank [handle] for this valuable post!" Clicking on this link will allow you to award a star, which helps others identify useful threads - and is a nice compliment to the person who helped you!

Anyone, welcome to the site :)

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top