HighDots Forums  

Need unique ids using include file

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss Need unique ids using include file in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
DanWeaver
 
Posts: n/a

Default Need unique ids using include file - 04-08-2008 , 05:41 AM






I have several sets of controls that are repeated. I am trying to use
include files to to the job so as to have my 'tablet' html in one
place.

<div id="0" class="tablet">
<!-- #include virtual ="tablet.inc" -->
</div>

<div id="1" class="tablet">
<!-- #include virtual ="tablet.inc" -->
</div>

<div id="2" class="tablet">
<!-- #include virtual ="tablet.inc" -->
</div>

I would like the id of each control in the repeated include file to be
unique- it doesnt matter what it is called but it must be unique to
the page.

tablet.inc has elements such as:

<input id="blah" name="blahname"
onkeyup="somejavascriptfunction(this)" />

which I need to be eg id="blah1" in the first div and id="blah2" in
the second or anything along those lines.

Any pointers on this much appreciated.

Dan

Reply With Quote
  #2  
Old   
Andy Dingley
 
Posts: n/a

Default Re: Need unique ids using include file - 04-08-2008 , 05:57 AM






On 8 Apr, 11:41, DanWeaver <danofwea... (AT) googlemail (DOT) com> wrote:

Quote:
I would like the id of each control in the repeated include file to be
unique
Well you just can't, so find something else to do.

One option is to not use includes, but instead to generate the content
dynamically (trivial bit of PHP loop or something). Then it would be
easy to generate the ids dynamically too.

Alternatively, given that you're already including each include inside
a wrapper that has a unique id, then you could re-write the client-
side JS or the form handler so as not to require unique ids on each
control. Instead they'd have to infer the "identity" of each control
from the unique id of their parent, in combination with some sub-
selector within this, such as the control type and a class name
attached to it that was unique within that parent (but shared with the
other includes).

Of the two, the first is likely to be easiest.


Reply With Quote
  #3  
Old   
Harlan Messinger
 
Posts: n/a

Default Re: Need unique ids using include file - 04-08-2008 , 06:43 AM



DanWeaver wrote:
Quote:
I have several sets of controls that are repeated. I am trying to use
include files to to the job so as to have my 'tablet' html in one
place.

div id="0" class="tablet"
!-- #include virtual ="tablet.inc" --
/div
You can't have id="0". An id can't start with a digit. Try id="div0".

Quote:
div id="1" class="tablet"
!-- #include virtual ="tablet.inc" --
/div

div id="2" class="tablet"
!-- #include virtual ="tablet.inc" --
/div
If you were using ASP, it would be

<% dim n
n = 0
%>
<div id="div<%=n%>" class="tablet">
<!-- #include virtual ="tablet.inc" -->
</div>
<% n = n + 1 %>

etc.

Quote:
I would like the id of each control in the repeated include file to be
unique- it doesnt matter what it is called but it must be unique to
the page.

tablet.inc has elements such as:

input id="blah" name="blahname"
<input id="blah<%=n%>" name="blahname"

Quote:
onkeyup="somejavascriptfunction(this)" /

Reply With Quote
  #4  
Old   
DanWeaver
 
Posts: n/a

Default Re: Need unique ids using include file - 04-08-2008 , 09:28 AM



Thanks guys,

I will use the asp route- works perfectly!

Dan


Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.