HighDots Forums  

Flexible Property Values

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Flexible Property Values in the Macromedia Dreamweaver forum.



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

Default Flexible Property Values - 03-26-2009 , 07:49 AM






QUESTION: Does anyone know the JavaScript necessary to assign a
calculated value to the width property of an HTML tag?

BACKGROUND: I am trying to overcome a problem with my expandable,
SPRY, horizontal menubar whose mathematical solution is sketched below. What I
need is the code that would permit me to assign the below calculated values to
the various width properties of the [LI] tags of a horizontal menubar.

The CALCULATION:

Variables

Z = Width of the [BULLET] tag (varies with size of window)
Y1 = Width of the first [LI] Tag (some fixed value measured in integer em
units)
Yi = Width of the each other [LI] Tag (a rounded, calculated width measured in
integer em units)
Yn = Width of the last [LI] Tag (a calculated integer value measured in em
units)
N = Number of [LI] Tags (any positive integer)

Formula

var Z = some value;
var Y1 = some value;
var N = some value;

function(Z, Y1, N) {
var Yi = INT((Z - Y1) / (N - 1));
var Z = Z;
var Y1 = Y1;
var N = N;
If (Z - (N x Yi) != 0) {
Yn = Yi + (Z - N x Yi);
}
return Yn Yi;
}

The integer values of Y1, Yi, and Yn would then be assigned to the respective
width properties of each of the [LI] tags.

SOURCE PAGE:
http://homepage.mac.com/moogoonghwa/Imagine_Prototype/Content/

Roddy :smile;


Reply With Quote
  #2  
Old   
Murray *ACE*
 
Posts: n/a

Default Re: Flexible Property Values - 03-26-2009 , 10:00 AM






I will just add that the problem with using heavy js to do stuff like this
is that without js, nothing happens. So, you would be penalizing those who
do not or are not able to use javascript in their browsing. Admittedly this
is demographic dependent, but why do it at all? Besides, it makes for a
pretty heavy, and very difficult to troubleshoot page.

So, I agree with your caveat expressed below, James....

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"James Shook" <user (AT) example (DOT) net> wrote

Quote:
P.S. Despite my previous answer I strongly doubt that using JavaScript to
write out this chunk of code is the way to go. I can't help but feel that
if you can't achieve your intended effect using static HTML and CSS, then
you are getting a bit too fiddly with the design of the page.

I gather this is yet another stage in your evidently never-ending quest to
make this page work as you envision. Perhaps you should step back and get
some perspective. If the design goal you are after can be achieved only
through dynamically-written code, perhaps you are fighting the medium, and
should just fix upon some reasonable values for these elements and move
on.

Just a thought.

JMS


Reply With Quote
  #3  
Old   
Michael White
 
Posts: n/a

Default Re: Flexible Property Values - 03-26-2009 , 10:17 AM



James Shook wrote:
Quote:
Investigate the JS "document.write" method to write HTML into your
document on the fly. You would use a combination of literal values (HTML
code) + variables to write dynamically the HTML you need. An (partial)
example:

I have written a script with the function:

function kakaduTime(offset)

When it is called in the page (see below) off we go to my script. A
bunch of stuff happens and my script ends with:

return ("Right now it is "+kDay+", "+kMonth+" "+kDate+" in Kakadu. This
is "+season+", "+seasonDescription[seasonIndex]+". ")


Now, in my HTML page I call my function like so:

p
SCRIPT language="JavaScript">document.write(kakaduTime(10 ))</SCRIPT
/p

How it works: In the HTML page, within the <p> tags is a call to my
script "kakaduTime" with the parameter 10 passed to it, which is mapped
to the variable "offset" in the JS function itself. (The value of the
parameter – 10 – is beyond the scope of this discussion. It works.) A
number of variables are calculated. Then the function returns a
character string which is made up of literals (like "Right now it is ")
and variable values (like the value of "kDay.") This results in a
character string which, today, looks like:

"Right now it is Thursday, March 26th in Kakadu. This is Gudjewg, or
monsoon season — the time of the heaviest rains. Rivers overflow their
banks and wildlife moves to high ground."

The in-line JS document.write writes this text into the page dynamically
when the page is loaded.

I did this so that whenever the page was viewed, the correct day and
season would be written into the text of the page dynamically. In a
month, if the same page were viewed, it would show that date and perhaps
a different season, along with its description.

In this case I am using document.write only to write the character
string returned by the function call. In your case you will have to
write actual HTML code, so you will have to learn how to escape
characters so they are not written just as text in your page.

JMS
WTF
MW


Reply With Quote
  #4  
Old   
Michael Fesser
 
Posts: n/a

Default Re: Flexible Property Values - 03-26-2009 , 12:04 PM



..oO(James Shook)

Quote:
Investigate the JS "document.write" method to write HTML into your
document on the fly.
document.write is ugly. The preferred and more reliable way today to
create HTML on the client is to use DOM scripting.

Quote:
[...]

I did this so that whenever the page was viewed, the correct day and
season would be written into the text of the page dynamically. In a
month, if the same page were viewed, it would show that date and perhaps
a different season, along with its description.

In this case I am using document.write only to write the character
string returned by the function call. In your case you will have to
write actual HTML code, so you will have to learn how to escape
characters so they are not written just as text in your page.
The OP just wants to apply some script-calculated widths, not create any
new HTML.

Micha


Reply With Quote
  #5  
Old   
kiusau
 
Posts: n/a

Default Re: Flexible Property Values - 03-26-2009 , 04:33 PM



[Q]The OP just wants to apply some script-calculated widths, not create any new
HTML.[/Q]
In effect, I am trying to change the property value of an HTML style attribute
on the fly, as neither the [BULLET], nor [LI] tags appear to be able to host
the width attribute.

You have certainly come closest to understanding the problem, however.

Roddy :smile;


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 - 2009, Jelsoft Enterprises Ltd.