944,038 Members | Top Members by Rank

Ad:
Jan 26th, 2007
0

Writing a javascript function

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Jan 26th, 2007
0

Re: Writing a javascript function

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:

HTML Syntax (Toggle Plain Text)
  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:

HTML Syntax (Toggle Plain Text)
  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 5:33 pm.
Reputation Points: 47
Solved Threads: 1
Posting Whiz in Training
Mushy-pea is offline Offline
271 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Html Woes
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Am I right here?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC