Connecting Tech Pros Worldwide Help | Site Map

Javascript question on displaying contents of a webpage in a portlet

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 9th, 2006, 04:55 PM
Brie
Guest
 
Posts: n/a
Default Javascript question on displaying contents of a webpage in a portlet

I have a user preferences page where users select what city they're
with. Once they choose that a certain page shows in a portlet on their
intranet page. I can't get this to work. Here's the code I have for
it to show those corresponding pages. Does anyone know what i'm doing
wrong? Any help would be greatly appreciated.

<script type="text/javascript">

for (var i = 0; i < cityName; i++)
if (cityName.toLowerCase() ==
cityName[i].cityName.toLowerCase())
{
open (weatherURL);
break;
}

var cityName = [
{ cityName: 'austin',
weatherURL: "austin.html" },
{ cityName: "albany",
weatherURL: "albany.html" },
{ cityName: "amsterdam",
weatherURL: "amsterdam.html" },
{ cityName: "beijing",
weatherURL: "beijing.html" },
{ cityName: "berlin",
weatherURL: "berlin.html" }

];


</script>


Thanks!
Brie


  #2  
Old February 9th, 2006, 05:35 PM
web.dev
Guest
 
Posts: n/a
Default Re: Javascript question on displaying contents of a webpage in a portlet


Brie wrote:[color=blue]
> I have a user preferences page where users select what city they're
> with. Once they choose that a certain page shows in a portlet on their
> intranet page. I can't get this to work. Here's the code I have for
> it to show those corresponding pages. Does anyone know what i'm doing
> wrong? Any help would be greatly appreciated.
>
> <script type="text/javascript">
>
> for (var i = 0; i < cityName; i++)[/color]

i < cityName ?

1. You're using cityName before you even have it defined.
2. You're comparing a number to an object.

You probably really meant this:

for(var i = 0; i < cityName.length; i++)
[color=blue]
> if (cityName.toLowerCase() ==
> cityName[i].cityName.toLowerCase())[/color]

Now you've confused me. Do you have in your form an element with the
name "cityName" ? The expression on the left hand side makes me assume
so. In which case, you should then access it properly:

if(document.forms["formName"].elements["cityName"].value.toLowerCase()
== ...)

And finally, where is your script defined? The way it is at the
moment, it'll execute right away. Meaning, since it's not contained in
a function and you're waiting for a response from the user, it's
useless.

  #3  
Old February 9th, 2006, 05:35 PM
web.dev
Guest
 
Posts: n/a
Default Re: Javascript question on displaying contents of a webpage in a portlet


Brie wrote:[color=blue]
> I have a user preferences page where users select what city they're
> with. Once they choose that a certain page shows in a portlet on their
> intranet page. I can't get this to work. Here's the code I have for
> it to show those corresponding pages. Does anyone know what i'm doing
> wrong? Any help would be greatly appreciated.
>
> <script type="text/javascript">
>
> for (var i = 0; i < cityName; i++)[/color]

i < cityName ?

1. You're using cityName before you even have it defined.
2. You're comparing a number to an object.

You probably really meant this:

for(var i = 0; i < cityName.length; i++)
[color=blue]
> if (cityName.toLowerCase() ==
> cityName[i].cityName.toLowerCase())[/color]

Now you've confused me. Do you have in your form an element with the
name "cityName" ? The expression on the left hand side makes me assume
so. In which case, you should then access it properly:

if(document.forms["formName"].elements["cityName"].value.toLowerCase()
== ...)

And finally, where is your script defined? The way it is at the
moment, it'll execute right away. Meaning, since it's not contained in
a function and you're waiting for a response from the user, it's
useless.

  #4  
Old February 9th, 2006, 06:15 PM
Brie
Guest
 
Posts: n/a
Default Re: Javascript question on displaying contents of a webpage in a portlet


web.dev wrote:[color=blue]
> Brie wrote:[color=green]
> > I have a user preferences page where users select what city they're
> > with. Once they choose that a certain page shows in a portlet on their
> > intranet page. I can't get this to work. Here's the code I have for
> > it to show those corresponding pages. Does anyone know what i'm doing
> > wrong? Any help would be greatly appreciated.
> >
> > <script type="text/javascript">
> >
> > for (var i = 0; i < cityName; i++)[/color]
>
> i < cityName ?
>
> 1. You're using cityName before you even have it defined.
> 2. You're comparing a number to an object.
>
> You probably really meant this:
>
> for(var i = 0; i < cityName.length; i++)
>[color=green]
> > if (cityName.toLowerCase() ==
> > cityName[i].cityName.toLowerCase())[/color]
>
> Now you've confused me. Do you have in your form an element with the
> name "cityName" ? The expression on the left hand side makes me assume
> so. In which case, you should then access it properly:
>
> if(document.forms["formName"].elements["cityName"].value.toLowerCase()
> == ...)
>
> And finally, where is your script defined? The way it is at the
> moment, it'll execute right away. Meaning, since it's not contained in
> a function and you're waiting for a response from the user, it's
> useless.[/color]



Here's where the script is defined. THis is another page:

<body>
<%
//Get portlet context object
IPortletContext portletContext =
PortletContextFactory.createPortletContext(request ,response);
IPortletResponse portletResponse = portletContext.getResponse();

//Get user name from incoming form, and set it into the
portletResponse
String cityName = request.getParameter("cityName");
if (cityName == null)
{
System.out.println("FHWeather: setUserPrefs: selected cityName is
null, set default albany");
cityName = "albany";
}

System.out.println("FHWeather: setUserPrefs: cityName = " +
cityName);

IPortletRequest portletRequest = portletContext.getRequest();
portletResponse.setSettingValue(SettingType.User, "cityName",
cityName);

System.out.println("FHWeather: setUserPrefs: cityName = " +
portletRequest.getSettingValue(SettingType.User, "cityName"));

portletResponse.returnToPortal();
%>
</body>
</html>

Thanks!

  #5  
Old February 9th, 2006, 07:25 PM
web.dev
Guest
 
Posts: n/a
Default Re: Javascript question on displaying contents of a webpage in a portlet


Brie wrote:[color=blue]
> Here's where the script is defined. THis is another page:
> <%[/color]
[snip][color=blue]
> %>[/color]

Where is the script defined? Posting server-side script is not very
useful. Instead, you should post what the client receives.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.