473,568 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Functions within the style="" attribute

144 New Member
I hope this is just a syntax issue, but I can call a function when a page is served up like this:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Function FFcolor(x)
  3.     Select case x
  4.     case 1: FFcolor = "#FF0000"
  5.     case 2: FFcolor = "something else"
  6.   etc.
  7. End Function
  8. %>
which called from my element "<a" within the style attribute like this
Expand|Select|Wrap|Line Numbers
  1. <a ... style="color: <%=FFcolor(x)%>; ... >
and the color is set to #FF0000 or something else.

But I can't find a similar way to call a javascript function like this
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function FFcolor(x) {
  3.     switch (x) {
  4.             case 1:  return "#FF0000";
  5.             case 2:  return "something else";
  6.    etc. }
  7. }
  8. </script>
from inside the
Expand|Select|Wrap|Line Numbers
  1. <a ... style="color: [ javascript function call?]; ... >
I want to change the font depending on the page, but use the same function for events.

Since I already have functions setup to do this for events (mouseover, etc) I want to use the same functions for initializing a new page (like a refresh). In other words, the color changes from some previous color when the page is presented, conditioned on a "pagename" variable, then changes onmouseover, and changes back to the first color onmouseout (without any onclick action). Each page starts out with its unique font color.

The mouseover & mouseout, and "I wish" the startup font color results should be based on the same function using the same "switch" subfunction.

I can use the first example, <%= %> for the startup color but not for the events (because of some further manipulation I do); and that means I have to have similar routines, "switch" and "Select Case" statements, in 2 locations, one for ASP and one for Javascript.

Repeating, I need some javascript syntax to call from inside the style=" attribute so that the pair color:value is really a color:function. I've tried a lot of ways without any errors but no color actually comes back in javascript. The result should be ... style="color: #FF0000; ... "or some other color"

Anybody?
Jan 14 '12 #1
4 6601
Dormilich
8,658 Recognized Expert Moderator Expert
what you try to do is not possible (with this approach). reason: in the first example you use a server-side script (ASP?). at this point, the whole HTML page is just a string inside the script. JavaScript on the other hand side works on the client and when it is invoked, the HTML source code is already rendered. hence there is no way to influence the output by changing the source code. what you need to do is change the page representation (the DOM tree) the browser generated.

for changing a CSS property you would have to set/alter the Element’s style object elem.style.color = "red"; (of course you could also use a function’s return value).
Jan 14 '12 #2
C CSR
144 New Member
Thanks Dormilich. That makes sense. I was trying to re-render the page or something like that and a little bit confused. I got it. Thanks for your time.
Jan 14 '12 #3
santoshk1
1 New Member
you can use by using below concept :

Expand|Select|Wrap|Line Numbers
  1. style="color: '+ fnGetPermission(name)+'"
  2.  
  3.  
  4. function fnGetPermission(name){
  5.         var permissionArray = localStorage.getItem("permissionArray").split(',');
  6.         if($.inArray(permissionArray) == true) {
  7.             return "red;
  8.         } else {
  9.             return "blue";
  10.         }
  11.         }
Dec 27 '17 #4
RockybBalboa
5 New Member
Calling a JS function from Server side method is not possible.
Feb 1 '18 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3038
by: Harry Pehkonen | last post by:
I have been defining new class methods when I'm trying to simplify some code. But I'm thinking I should just define functions within that method because they aren't useful from the outside anyway. Example: Before: class Mess(object): def complicated(self, count):
2
1895
by: D. Alvarado | last post by:
Hello, I am outputting HTML from an XSLT and I am having trouble setting the value of a form-action field based on certain conditions. Here is the non-working code: <xsl:template match="dictionary-link"> <form name="dictionaryform" method="get" action="<xsl:choose><xsl:when...
0
1179
by: hazz | last post by:
I would like to have an attribute stand as a gatekeeper to a method. What I don't want to do is hard code a user's role into the attribute as follows. public void DoSomething(){ //only users with a "PartiallyTrusted" role can access this method. } Is it possible to make a database call from the attribute to obtain the role, perhaps...
22
5298
by: John Salerno | last post by:
I might be missing something obvious here, but I decided to experiment with writing a program that involves a class, so I'm somewhat new to this in Python. Anyway, what is the best way to create a function (A) within a class that another function (B) can use? Function A is not something that an instance will ever call, so I figure it's a...
0
1050
by: Mike | last post by:
Hi. I have a vb.net/asp.net application, originally created in VS2003. I'm upgrading it to VS2005, and have found that Public Functions in a module are no longer accessable in my application. My code looks like this - and in this example I cannot call Function 123 within my application. --- Public Module ABC Public Function 123() as...
2
1837
by: wiggy | last post by:
Hello! I am new to this site and very new to C programming. I am writing a basic GUI in Turbo C which I can do with relative ease. However, our teacher has given us a C file whichwhen run, can control things on a circuit board. My GUI runs fine, and the the teachers program runs fine aswell. However, what I want to do is to be able to call...
3
1439
by: dgunjal | last post by:
Is there any method by which i can invoke C++ class functions within C functions?
1
5705
by: kaens | last post by:
So, I have a class that has to retrieve some data from either xml or an sql database. This isn't a problem, but I was thinking "hey, it would be cool if I could just not define the functions for say xml if I'm using sql", so I did some fiddling around with the interpreter. First, I try conditionally creating a function, period: a = 'a'
2
2058
by: =?Utf-8?B?SnVsaWFu?= | last post by:
My first problem is: I am having an issue when using a web service. The web service is written by another department and say its running fine but when I call it, I sometimes I get a system.net.webexception return instead of the correct return. Would anyone have any advice or suggest any extra debugging I could do to find out where this problem...
9
1648
by: arnaudk | last post by:
Is it possible for a constructor or a function within it to throw an exception? When I declare an object within a try { } block to subsequently catch any exceptions the constructor or functions therein may throw, the code will not compile, citing that the object in question is an undeclared identifier (presumably because it's enclosed in a try{}...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.