Using Prototype Framework With Hide And Show Function
Mar 22, 2010
I'm learning how to use Javascripts and using Prototype framework by following a step by step tutorial from a book. Unfortunately when I stepping through the following code:[code]
how to use Javascripts and using Prototype framework by following a step by step tutorial from a book. Unfortunately when I stepping through the following code:
Code: <html> <head> <title>
[Code]....
The prototype file can be acquired at Prototype website download
I have been staring at this problem for too long and most likely missing a simple solution so I hope somebody can take my blindfold off and show me the way The markup (which comes from a CMS and I cannot change it) I am working with is akin to:
Notice how the second fo 3 FAQ sections has 2 paragraphs under the 'trigger' rather than 1? Therein lies my problem, because what I am doing with prototype.js is:
1.) Loop through page and collect all <p>'s 2.) do a .each iteration and attach an onclick event on $$('p strong.open') - assume this node for each iteration is now var 'trigger' 3.) run Element.hide() on trigger.next() 4.) in the onclick event, run Element.show() for trigger.next()
- If you are still following so far - my problem is that next() only shows/hides one single element and that is the <p> holding the content - which is fine except when there are 2 or even more <p>'s with content I need to act on. I;ve experimented with nextSiblings and adjacent() and I end up with too many nodes - basically every <p> in the entire document. I just want 'hide all P's after the trigger P up until the next p > strong.open
I have 3 divs that contain radio with labels and beneath each radio button I would like to show/hide a form based on whether the radio is selected or not.
Code idea:
So if the radio1 input is selected this would show form1. Selecting radio2 input would hide any other forms (form1, form3) and show form 2 etc.
I am trying to hide/show table when hide/show button is pressed
Problem: The code works fine when I remove 'slow' from line 10. But with 'slow' in line 10 content of toggleButton doesnt change from Hide to Show when pressed.
According to ECMAScript, the root of the prototype chain is Object.Prototype. Each object has an internal property [[Prototype]] that could be another object or NULL.... However, it also says that every function has the Function prototype object: Function.Prototype, it confused me, because a function is an object, for a function object, what is its function prototype and object prototype..For example:
var x = function (n) {return n+1;};
what is the relationships of x, Object.Prototype and Function.Prototype
I am trying to get to the bottom of javascript object, prototypes etc. I have a fairly good grasp of it, but I get confused the closer I get to the base object.prototype. FIrst of all, I was under the impression that all objects descend directly from Object. But some objects (like Array) seem to inherit properties and methods from the function.prototype. So does this mean that the chain is like this:
object -- function -- array Second, I noticed (on the mozilla javascript reference site that object.prototype inherits properties and methods from function.prototype and vice versa!? How can this be? I must be missing something important about understanding the chain?
I need an 'unobstrusive DOM' function which will show and hide a piece of text within the DIV activated by links. Can anyone help me find a suitable function?
<div id="formatting"> <h3>Formatting options</h3>
<dl> <dt>Bold</dt> <dd>[b]text[eb]</dd> <dt>Italic</dt> <dd>[i]text[ei]</dd> <dt>Link</dt> <dd>link [l=url]text[el]</dd> <dt>Line break</dt> <dd>single new line</dd> <dt>Paragraph</dt> <dd>double new line</dd>
The below is a menu, which is hidden until clicked, and can be hidden by clicking it again.
<!-- This goes in the HEAD of the html file --> <script language="javascript"> <!-- function showIt() { if (document.layers) {document.layers["layer1"].visibility='hide'} else {document.all["layer1"].style.visibility='hidden'} } function hideIt() { if (document.layers) {document.layers["layer1"].visibility='show'} else {document.all["layer1"].style.visibility='visible'} } // --> </script>
<span id="layer" style="position:absolute; top:17; left:20; width:250; height:90; visibility:show"> <script> <!-- author: bfsog@hotmail.com use it as you wish //--> <!-- function buttonText(type) { if (type=="Hide Menu ") {document.menu.button.value="Menu";} else {document.menu.button.value="Hide Menu ";} showIt(); if (document.menu.button.value=="Hide Menu ") {hideIt();} } // -->
<!-- change the value of 'top' and 'left' in the layers properties below to place the menu in the desired position matching the placement of the button --> </script>
I have a script to show and hide various divs based on a function & var. The problem I am having is that when ANY of the variables ('hate', 'ok' and 'love') are passed all 3 different feedback forms ('FeedbackHate', 'FeedbackOk' and 'FeedbackLove') appear, not just the one I want.
Here is the JS: function sitesurveyswitch(emotion) { var e = emotion; document.getElementById('site_survey_hate').style.backgroundPosition = '0px 0px'; document.getElementById('site_survey_ok').style.backgroundPosition = '0px 0px'; document.getElementById('site_survey_love').style.backgroundPosition = '0px 0px'; document.getElementById('FeedbackHate').style.display = 'none'; document.getElementById('FeedbackOk').style.display = 'none'; document.getElementById('FeedbackLove').style.display = 'none'; if (e == 'hate') document.getElementById('site_survey_hate').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackHate').style.display = 'block'; if (e == 'ok') document.getElementById('site_survey_ok').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackOk').style.display = 'block'; if (e == 'love') document.getElementById('site_survey_love').style.backgroundPosition = '-80px 0px'; document.getElementById('FeedbackLove').style.display = 'block'; }
And here is the code related to this function: <div id="siteSurveyBox"> <span id="site_survey_hate" onclick="sitesurveyswitch('hate');return false;"></span> <span id="site_survey_ok" onclick="sitesurveyswitch('ok');return false;"></span> <span id="site_survey_love" onclick="sitesurveyswitch('love');return false;"></span> </div> <div id="FeedbackHate" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div>
<div id="FeedbackOk" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div> <div id="FeedbackLove" style="display:none; margin-top:-28px;"> FEEDBACK FORM IS HERE </div>
I am very new to javascript and html. I am trying to create a function which will hide or show a div (div1). Right now, it is always showing the div whether the boolean value is true or false. I know that it is getting inside the else if part, but it doesn't seem to be working.
<script type="text/javascript"> function hideDiv(flag){ if (flag == false){ document.getElementById('div1').style.visibility="visible"; }else if (flag == true){ document.getElementById(div1).style.visibility="hidden"; }} var bool = new Boolean(true) hideDiv(bool); </script><body> <div id="div1"> Text! </div></body>
I have a simple FAQ show/hide function set up however I am having trouble setting up an if clause. My code is: $(document).ready(function(){ $("dd").hide(); $("dt").click(function(){ $("dd").hide('slow'); $(this).next().slideToggle(); }); });
However, when you click on the same item twice it firstly hides and then reshows it, I need an if statement that basically states; if "this?!" is visible/shown Then do nothing else $("dd").hide('slow'); $(this).next().slideToggle(); I am unsure of the syntax and can't figure out what property I can trace out to see if the item is being shown or not.
I have 2 divs on the page, div1 has a gif animation in it and div2 is the page content. I want to hide div2 and only show div1 which plays the gif, then after some time div1 fades away and div2 fades up to show the page content.
This is my thought process:
1) On doc ready, hide div2 2) after 3000 fade div1 out 3) fade div2 in
$(document).ready (function(){ $('#div2')hide();
but I dont know how to fade out the div after a time and fade in the other div.
So in the past I've mostly just copy and pasted other JavaScript functions I needed, and made slight modifications based on my exact needs. However, this time I couldn't find anything that would work with what I wanted to do (show and hide comments on news stories in a particular way), so I decided to just make my own.After a few hours of messing around with it, I'm quite exasperated, because what I have looks like it should work, but for some reason I can't identify, doesn't.Essentially what it should do is, find the table with the ID of the news article whose comments are being toggled, then find all the rows in the table that are labeled as comments, and either show them or hide them, based on their current state (as defined by their class with a "display: none;" in it or not).
Obviously it uses PHP, but I know that's not the problem; it just uses the article's ID number to pass on which comments need to be hidden/shown to the function.From everything I've looked up, this should work, but doesn't. Something peculiar, though, is that the function looks like it's not even being called; I put a simple alert('Test'); in the function, and still nothing happened when I clicked the link. So maybe my function is fine in itself, but I'm just calling it in an incorrect manner?
I have a table that Im hiding during the initial load that has a considerable amount of data. (I dont design'em, I just code 'em).
During the .show, .hide ... functions I would like to display a please wait msg. But I cant seem to find a way to do an async function. As the callback functions only deal with sync ...(I think)
I have a table that contains many rows, some in italian with code <td nome='riga_i'>. and some in english with code <td name='row_e'>. I have created two buttons with different background flags: italy and uk, so when one pushes the button with flag uk, the html page will be reloaded with only english rows, and when one pushes the button with flag it, the same page is reloaded containing only italian rows. All the code posted here works well, but I think that the code can be better because to reach this result I had to dupplicate the same function and I don' t like this.
Here the code:
To better the code I have tried in this way but without success ...
just started using jQuery,and i'm having a problem using the function .show()/.hide() to make a div appear and disapear when a certain option value is selected.It's working fine in firefox but not working at all in chrome and IE 8.This is the function code i'm using :
I have a function that uses the ajax load function to post off some parameters and fill a div with the returned content after a db query has been run to create it. This all works fine, however I would like to be able to replace the div with a loading graphic whilst the content is generated. I assumed this was done by placing the graphic at the start of the function, then using a callback function to remove it and display the actual data once it has been fully generated...
However when I trey to implement this I am getting a strange result in that the callback fires before the content is generated. So my loading graphic disappears and then the content appears sometimes 10 seconds later. How can I ensure the call back only executes once the new content is ready to be displayed ??
Here's my code ... function get_report(){ // Hide #report_here div and show loading graphic here ... $("#report_here").load("/admin/reports/statistics_report/", { // Parameters sent go here }, finished() ); function finished() { // Hide loading graphic and show #report_here div here ... }
I have a table that contains many rows, some in italian with code <td nome='riga_i'> and some in english with code <td name='row_e'>. I have created two buttons with different background flags: italy and uk, so when one pushes the button with flag uk, the html page will be reloaded with only english rows, and when one pushes the button with flag it, the same page is reloaded containing only italian rows. All the code posted here works well, but I think that the code can be better because to reach this result I had to dupplicate the same function and I don' t like this.
Here the code:
To better the code I have tried in this way but without success ...
I always want "smenu3" to show with "smenu4" and "smenu5" collapsed... When the user clicks the link, it calls a javascript function to show "smenu4" like so...
I am trying to use the sortBy function in the prototype.js library. Nevertheless, I can't work out what to include in the iterator function. Can someone shed some light on this?
Array.prototype.each = function (fn) { this.map(fn) }
This is my each function that works great in every other browser but IE. UGH! What am I doing wrong? the error points to the this in the function. Is it that IE doesn't like map? Has anyone seen this before? I thought my code was correct. Works perfect in FF, chrome and opera. the canvas text doesn't work in opera, but it does render the features so the each function is working.
I'll post the code if needed, but it's huge. here's the script running.[URL]..