How to use a javascript in a page

This is an open forum for any mojoPortal topics that don't fall into the other categories.

This thread is closed to new posts. You must sign in to post in the forums.
3/15/2012 9:21:48 AM
Gravatar
Total Posts 1

How to use a javascript in a page

I have a javascript slide show of images which I want to include only on a single page. I have the folder of the javascript with the custom CSS and images. Can anyone please help as where to place and how to go about it.

 

Sudeep

3/15/2012 11:58:56 AM
Gravatar
Total Posts 115
mojoPortal Community Expert

Re: How to use a javascript in a page

You could just use the Slide Show that is build into to HTML Content. All that you need to do is wrap the images in a DIV or P element and turn on the slide show from the feature settings. Here is a write up and short video that Joe Davis has done.

If you need to use the current scripts you are running the best method would be as follows:

  • Add the script tag to the layout.master and point it to you file. Add any initialization that the script requires.
  • Add you CSS to the style.css file for you skin. Or you can create a separate CSS file but you will have it to the style.config file so it will be loaded.
  • You can then use the HTML content control to create you markup.
5/17/2012 11:29:08 AM
Gravatar
Total Posts 24

Re: How to use a javascript in a page

When I put javascript on a page it breaks the skin only in IE.  Chrome and Firefox works fine.

http://www.thefitgirls.com/tdee-calculator.aspx

Take a look on the right side of the page.

I can't figure out why

5/17/2012 11:53:04 AM
Gravatar
Total Posts 18439

Re: How to use a javascript in a page

When I view the source of your page I see 2 problems:

<SCRIPT src="Data/Sites/1/flash//tdee.js" type=text/javascript></SCRIPT>
<form method="post" style="width: 400px; height: 111.28%" name="tdeeform">

1. there is an extra / in the url for your script

2. You've embedded a <form element. In ASP.NET WebForms there can be one and only one form element on a page and one already exists (in layout.master it wraps all the content) so you cannot add one in the html content feature without breaking things.

Hope that helps,

Joe

5/17/2012 12:02:42 PM
Gravatar
Total Posts 24

Re: How to use a javascript in a page

Thanks Joe,

Is there any way to use javascript controls like textboxes and buttons on the client side without using a form?  Or would I have to develop this as a module on the server side to get the functionality I want?

Thanks

 

5/17/2012 12:17:19 PM
Gravatar
Total Posts 18439

Re: How to use a javascript in a page

You can use javascript, textboxes and buttons if it doesn't need to do postback but only does client side manipulation with javascript ie if your calculator is all javascript it would not necessarily need to postback, it could read the values from the textboxes and update a span or div with the results all client side with no postback, so the button click would not submit the form it would just invoke your javascript.

If you need to postback then you need to develop  a custom feature and use <asp:TextBox, <asp:Button etc, that way you are posting back using the form that already exists. To make it play nice with other features on the page you would wrap it in an UpdatePanel so the post back would use ajax and not affect other modules on the page. In that case it would seem easier to implement the calculator with server side code that executes on postback rather than javascript, you could use the hello world example as a starting point.

Hope that helps,

Joe

5/17/2012 12:33:11 PM
Gravatar
Total Posts 24

Re: How to use a javascript in a page

It is all client-side.

How do you pass the textbox values to javascript without using a form then?

usually onbutton click I have passed in the form like:

function dosomething(form)

{

var MyValue = form.textbox.value;

//dosomething

return MyValue;

}

Thanks again for your help.  Sorry I am making you work for a beer...

 

5/17/2012 12:50:57 PM
Gravatar
Total Posts 18439

Re: How to use a javascript in a page

You would change the signature of your function to just function dosomething()

You would have to use unique ids on your textboxes and then you can get a reference using the id. Since jQuery is already included in the page you can use jquery to simplify the syntax

For example you have:

<input id="weight" size="5" name="weight" type="text" />

in js:

var weight = $("#weight").val();

read some jquery tutorials and you'll find how to do about anything you want.

without jquery the same example would be:

var weight = document.getElementById("weight").value;

Hope that helps,

Joe

 

5/17/2012 12:55:06 PM
Gravatar
Total Posts 24

Re: How to use a javascript in a page

It does,

Thanks as always Joe

5/17/2012 12:59:50 PM
Gravatar
Total Posts 18439

Re: How to use a javascript in a page

Thanks for the beer!

Cheers,

Joe

You must sign in to post in the forums. This thread is closed to new posts.