User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,929 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,707 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1107 | Replies: 1
Reply
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Writing a javascript function

  #1  
Jan 26th, 2007
Hi everybody

I am trying to develop an application, in which i want your help and suggestions.

I have a master page and many content pages. I want to write a javascript function in the master page script, and call that function in body onload.

I have a field in User table, which has the CSS files choosen by that user. The field value is just the file name, but not with extension .css
I have a stored procedure which retuns this CSS field values, if supplied userid.

The problem is that, I am not getting an idea how to write the function, which executes the stored procedure, taking userid as parameter, and then get the returned value, adding a .css extension to that, and assiging that field value.css to the href of the link?

Can anyone please help me in this?

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: UK (Bristol)
Posts: 225
Reputation: Mushy-pea is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
Mushy-pea's Avatar
Mushy-pea Mushy-pea is offline Offline
Posting Whiz in Training

Re: Writing a javascript function

  #2  
Jan 26th, 2007
From what you say, it sounds like your stored proceedure is a server side script that returns some stored information about a user's preferences when the user logs in. If this is so I would advise the following. Get the stored proceedure to serve a page with a script in it that sets a cookie:

  1. <body>
  2. <script type="text/javascript">document.cookie='user_info=my_style_sheet;
  3. expires=Fri, 26 Jan 2007 21:08:00; path=http://your_domain.com';
  4. setTimeout("set_link()", 2000)</script>

You can find info about how to correctly set a cookie here. So, the server side script generates the correct javascript code to set a cookie when that code is run on the client machine. Then, make your javascript app. read the cookie and set the link based on this:

  1. <head>
  2. <script type="text/javascript">
  3. function set_link() {
  4. var cookie = document.readCookie('user_info');
  5. var crumbs = cookie.split(=);
  6. var style = crumbs[1];
  7. var file_name = style + ".css";
  8. document.write("<a href=\"file_name\">Your style</a>");
  9. }
  10. </script>

A couple of things to note here:

1. This is a rough sketch of what you might need to do. I'm not an expert so there might be mistakes in there.

2. Remember that your server side script will need to generate the correct javascript code to set the cookie in the first place, or this won't work.

Hope this gives you some ideas.

Steven.
Last edited by Mushy-pea : Jan 26th, 2007 at 4:33 pm.
Hello, you're through to Steven on the BT Business technical help desk. Could I take your broadband telephone number please?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:09 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC