No javascript/jQuery within html content?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/10/2011 10:02:38 PM
Gravatar
Total Posts 21

No javascript/jQuery within html content?

Can I not embed javascript/jQuery within the html content objects on a page? Or can I only do this using a ContentModule?

I really didn't want to create a user control for the following code which will appear in only one page:

<div id="CustomerStatus">
<button name="button_ReturningCustomer" onclick="returningCustomer" type="button">I am a Returning Customer</button><button name="button_NewCustomer" onclick="newCustomer" type="button">I am a New Customer</button></div>

<script language="javascript" type="text/javascript">

$(document).ready(function () {
var customer = getCookie("customer");

if(customer != null && customer != "")
{
$("#CustomerStatus").hide();
}

});

12/11/2011 2:24:24 PM
Gravatar
Total Posts 21

Re: No javascript/jQuery within html content?

I found a post by Joe saying that code placed inside html content features should run as expected. Mine is not executing at all when I step through it in Firebug.

I thought that jQuery code would work automatically within mojoPortal but the $document.ready(function() is never touched at all. What do I need to do?

Here is my code:

<div id="CustomerStatus">
<button name="button_ReturningCustomer" onclick="returningCustomer" type="button">I am a Returning Customer</button><button name="button_NewCustomer" onclick="newCustomer" type="button">I am a New Customer</button></div>
<script language="javascript" type="text/javascript">

$(document).ready(function () {
var customer = getCookie("customer");

if(customer != null && customer != "")
{
$("#CustomerStatus").hide();
}

});

function returningCustomer
{
}

function newCustomer
{
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}

</script>

 

12/11/2011 2:26:59 PM
Gravatar
Total Posts 18439

Re: No javascript/jQuery within html content?

You should be able to do things like that in the Html Content feature using html view in the editor but it looks incorrect and incomplete to me.

Where is the function getCookie?

Where are those functions you list in onclick?

Even if those functions were there shouldn't it be onclick="newCustomer();" not onclick="newCustomer"

The code you posted is only going to run when the page first loads, it won't fire after the button click.

12/11/2011 2:30:50 PM
Gravatar
Total Posts 18439

Re: No javascript/jQuery within html content?

several mistakes in your code as posted

you should try getting it working in a plain html file first to make sure it works before you paste it in the editor.

12/11/2011 3:19:31 PM
Gravatar
Total Posts 21

Re: No javascript/jQuery within html content?

Thanks for the tip. I didn't have code inside the function blocks yet as I was just trying to get the $(document).ready() function to execute when the page loaded. The problem was the lack of parentheses following the function names.

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