sonesay
Feb 28 2009, 12:37 AM
OK I have attached an image of the structure of the HTML. I need help on figuring out a good method to be able to: 1. move div sections up or down the order. 2. change div sections child attributes depending on their position in the order 3. update order to database with Ajax (State of order has to be save to MySQL). There is only one function 'moveItem(direction, id, this)' that is used to move items (div_method_container_n*) around. These div_method_container_b* sit inside a parent div div_method_container_all so it makes grouping them a lot easier. I am using images for the buttons and have use an onclick="moveItem(direction, id, this)" attribute assigned to them. the current state I have it up to so far is I am able to move items around but I can only get access to the current div that I am working on so I can only change the attributes there. i.e modify the moveItem() only for the div with the button being clicked on. I cannot figure out a way to transverse to the next div and modify its moveItem() according so its up to date and will function correctly when clicked on. I am after suggests on ways to do this or even a complete rework on the solution so I can get a better functioning application. CODE function moveItem(direction, id, obj) { var parent = obj.parentNode; var grandParent = parent.parentNode;
var ipHidden; var hNodes = parent.childNodes; for(var i=0;i<hNodes.length; i++) { if(hNodes[i].tagName == 'INPUT') { ipHidden = hNodes[i]; break; } } // move items around if(direction == 'down') { jQuery(grandParent).insertAfter(jQuery(grandParent).next()); jQuery(obj).attr("onClick","moveItem('down', "+(id+1)+", this)"); jQuery(ipHidden).attr("Value",id+1); } else if(direction == 'up') { jQuery(grandParent).insertBefore(jQuery(grandParent).prev()); jQuery(obj).attr("onClick","moveItem('up', "+(id-1)+", this)"); jQuery(ipHidden).attr("Value",id-1);
} } I had to use a combination jQuery and regular javascript because somethings seem easier to do with one or the other. like I said any suggestions for improvement appreciated thank you.
Comment/Reply (w/o sign-up)
truefusion
Feb 28 2009, 07:14 AM
Uh, here's my version of it, at least the view. It imitates a selected item and moves only the selected item up or down depending on which button is pressed. Since its selection is kept track by IDs, i used hidden INPUT elements to keep track of their number. If you notice, the INPUT have a name as "item[]", so when you send the form, the server side script would (or should) receive an array in the order that the items are ordered in. I have not tested this script any further than what i have provided, so you'll have to see for yourself whether it can be implemented or if it is useful for you. I believe it performs most of the work you are trying to do concerning the view of the form from what i can understand in your post. CODE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>untitled</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script src="/path/to/jquery.js"></script> <script> var children; var index;
$(document).ready( function (){ children = $("#container").children("div");
$("#container div").click(function () { $("div#selected").removeAttr("id"); $(this).attr("id", "selected"); index = $("#container div").index(this); }); } );
function updateChildrenList(){ children = $("#container").children("div"); index = $("#container div").index($("#container div#selected")); }
function moveItemUp(){ if (index > 0){ $("#container div#selected").insertBefore($(children[index-1])); } updateChildrenList(); }
function moveItemDown(){ if (index < (children.length-1)){ $("#container div#selected").insertAfter($(children[index+1])); } updateChildrenList(); } </script> <style> #container { padding: 3px; border: 1px solid black; }
#container div { margin: 3px; padding: 5px; background-color: #EEE; border: 1px solid #CCC; }
#container div#selected { border-color: #999; }
h3 { margin: 0; } </style> </head> <body>
<div id="container"> <button onclick="moveItemUp();">Up</button> <button onclick="moveItemDown();">Down</button> <!-- --> <div> <input type="hidden" name="item[]" value="1"/> <h3>One</h3> </div> <!-- --> <div> <input type="hidden" name="item[]" value="2"/> <h3>Two</h3> </div> <!-- --> <div> <input type="hidden" name="item[]" value="3"/> <h3>Three</h3> </div> <!-- --> </div>
</body> </html>
Comment/Reply (w/o sign-up)
sonesay
Feb 28 2009, 08:57 AM
Yeah you have got my problem solved truefusion and surprisingly with little code. I am just reviewing your javascript code and am still a little confused on how the variable 'index' the the function call of index() is used. Could you please explain how it works in your javascript code, in the http://docs.jquery.com/Core/index example I am guessing the index() returns an index number based on the current position it is in of similar elements in our case divs? I've managed to get my version of the code to work correctly minus the ajax and mysql update at this point but the code is very long and there may be some code I can remove. I will post it up just for the sake of sharing but I am still in the process of improving it and reviewing your method then I will choose what to carry on with. CODE function moveItem(direction, id, obj) { var parent = obj.parentNode; var grandParent = parent.parentNode;
var ipHidden; var hNodes = parent.childNodes; for(var i=0;i<hNodes.length; i++) { if(hNodes[i].tagName == 'INPUT') { ipHidden = hNodes[i]; break; } } // get nodes. var div_headerNode = obj.parentNode; var div_methodContainerNode = div_headerNode.parentNode; var div_methodContainerOtherNode; var div_methodContainerAll = div_methodContainerNode.parentNode; // move items around if(direction == 'down') { if(id <= div_methodContainerAll.childNodes.length - 1) { for(var i=0; i < div_methodContainerAll.childNodes.length; i++) { if(div_methodContainerNode == div_methodContainerAll.childNodes[i]) { div_methodContainerOtherNode = div_methodContainerAll.childNodes[i+1]; } } // set other nodes values div_methodContainerOtherNode.firstChild.lastChild.value--; var imageButtons = div_methodContainerOtherNode.firstChild.getElementsByTagName('img'); imageButtons[0].setAttribute("onclick","moveItem('up', "+(id)+", this)"); imageButtons[1].setAttribute("onclick","moveItem('down', "+(id)+", this)"); // set current nodes values and shuffle jQuery(grandParent).insertAfter(jQuery(grandParent).next()); jQuery(obj).prev().attr("onClick","moveItem('up', "+(id+1)+", this)"); jQuery(obj).attr("onClick","moveItem('down', "+(id+1)+", this)"); jQuery(ipHidden).attr("Value",id+1); } } else if(direction == 'up') { if(id > 1) { // get other node for(var i=0; i < div_methodContainerAll.childNodes.length; i++) { if(div_methodContainerNode == div_methodContainerAll.childNodes[i]) { div_methodContainerOtherNode = div_methodContainerAll.childNodes[i-1]; } } // set other nodes values div_methodContainerOtherNode.firstChild.lastChild.value = id; var imageButtons = div_methodContainerOtherNode.firstChild.getElementsByTagName('img'); imageButtons[0].setAttribute("onclick","moveItem('up', "+(id)+", this)"); imageButtons[1].setAttribute("onclick","moveItem('down', "+(id)+", this)"); // set current node and shuffle around jQuery(grandParent).insertBefore(jQuery(grandParent).prev()); jQuery(obj).attr("onClick","moveItem('up', "+(id-1)+", this)"); jQuery(obj).next().attr("onClick","moveItem('down', "+(id-1)+", this)"); jQuery(ipHidden).attr("Value",id-1); } } } Thanks yet again for another awesome code truefusion. One last thing I have not been able to find out about is using jQuery selectors. Typically you would pass it a string expression to get your object for instance $('#idhere'); but I am trying to find a way where I can pass it an existing object and then filter it down some more with another string expression like $(object+"new expression here"); but it does not obviously work that way. Is there another method of achieving this?
Comment/Reply (w/o sign-up)
truefusion
Feb 28 2009, 10:29 AM
QUOTE (sonesay @ Feb 28 2009, 03:57 AM)  Could you please explain how it works in your javascript code, in the http://docs.jquery.com/Core/index example I am guessing the index() returns an index number based on the current position it is in of similar elements in our case divs? I don't fully understand how it works either  , i just tried to mirror the example the best i could, as that seemed the only possible way of getting what i wanted. I didn't think i had to repeat "#container div" to get it to work, which was the reason why it took me a few tries to get the proper index instead of "-1" to show up. QUOTE (sonesay @ Feb 28 2009, 03:57 AM)  Typically you would pass it a string expression to get your object for instance $('#idhere'); but I am trying to find a way where I can pass it an existing object and then filter it down some more with another string expression like $(object+"new expression here"); but it does not obviously work that way. Is there another method of achieving this? I've only done similar but with variables: $("#"+var). I believe in your example, object = $("exp"), which would be like saying $($("exp")+"exp2"). If that's the case, then you would use the selector method to retrieve the expression passed; that is, $($("exp").selector+"exp2"). However, this method doesn't work in cases of $(this). Since selector was introduced in version 1.3 of JQuery, if you have an earlier version, you'd have to update your copy of JQuery.
Comment/Reply (w/o sign-up)
(G)
Nov 17 2009, 05:33 AM

OK I have attached an image of the structure of the HTML. I need help on figuring out a good method to be able to:
1. Move div sections up or down the order.
2. Change div sections child attributes depending on their position in the order
3. Update order to database with Ajax (State of order has to be save to MySQL).
There
Is only one function 'moveItem(direction, id, this)' that is used to
Move items (div_method_container_n*) around. These
Div_method_container_b* sit inside a parent div
Div_method_container_all so it makes grouping them a lot easier.
I
Am using images for the buttons and have use an
Onclick="moveItem(direction, id, this)" attribute assigned to them. The
Current state I have it up to so far is I am able to move items around
But I can only get access to the current div that I am working on so I
Can only change the attributes there. I.E modify the moveItem() only
For the div with the button being clicked on.
I cannot figure
Out a way to transverse to the next div and modify its moveItem()
According so its up to date and will function correctly when clicked
On. I am after suggests on ways to do this or even a complete rework on
The solution so I can get a better functioning application.
Comment/Reply (w/o sign-up)
Similar Topics
Keywords :
- Javascript Game
Free online dice game called "Greedy" (6)
Re-learning Javascript
(3) As rusty as I was with ActionScript when I started my new job, I'm even rustier at JavaScript.
I'm trying to generate a new div on a webpage, containing an html file that (at the moment)
holds only a simple .gif image. The page looks like this at the moment: function
creatediv(id, html, width, height, left, top) { var newdiv =
document.createElement('div'); newdiv.setAttribute('id', id); if (width)
{ newdiv.style.width = 300; } if (height) { newdiv.style.height = 250; }
if ((left || ....
Need Help With Javascript Drag And Drop Script
Having trouble with javascript drag and drop script. (3) hi, i have been trying to create a drag and drop menu for my new website, so that the navigation
menu can be moved around the site. This is the code i have: CODE Test run - Right click
menu function coordinates(event) { if (event.button==2) { var x=event.x; var y=event.y; }
document.getElementById("element").style.left=x; document.getElementById("element").style.top=y;
document.getElementById("element").style.visibility="visible"; var oldx=x; var oldy=y;
window.onmouseup=end(); window.onmousemove=coordinates(event); } function end() { } #el....
Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working
(4) I am not able to adjust frames length/width in a frameset using java script functions I am using
firefox 3. In below code changerows is not working for me. Where as same is working in IE6.
Please help me in resolving this issue. Note: here frameset1 is the name given to the FRAMESET.
CODE function changeRows() { parent.frameset1.rows="30%,70%" }function restoreRows() {
parent.frameset1.rows="50%,50%" } ....
Java Vs Javascript
(11) I thought they were completely different things. Surely javascript should be seperated from the rest....
Document.write & Noscript Questions (javascript)
(2) I am trying to use javascript to include a stylesheet depending on the user's resolution. The
HTML CODE " /> id) { initEditor(); } ?> if
(screen.width>=1050) { document.write(' '); } I'm running into two
problems. 1) The script doesn't seem to be writing anything. Fixed 2) The tags cause all
sorts of validation errors. From what I've read it seems as though the tag is not allowed
within the section -- is this correct? Could the same thing be accomplished just putting the
default style....
Flash And Javascript Interaction
swfobject js questions (1) I don't know if anyone on here is familiar with this script. You can check it out here .
Basically it's a script that is supposed to give you javascript control over a flash object. I
am using it for a flv player. My question is this. I would like to display the current file's
title in a span element on the page, but the function described to gather the information for the
current file doesn't seem to work for me. The function, as outlined on on this page looks
like this: CODE function getUpdate(typ,pr1,pr2,swf) { if(typ == 'state'....
Javascript Object Node Referencing Help
(5) I've got two buttons with an onclick event to set the hidden input field to a certain value then
continue submitting the form. I have more than one form on display on the page and I don't want
to use ids. Is there a way I can reference it from the button/button onclick event? the forms is
laid out like this echo" "; echo" "; echo" Edit "; echo" Delete "; echo" ";
So basically the idea is to fire off new_modify function and start referencing the hidden input type
with name of do and set it to the supplied argument then continue submitting t....
Capturing Username Of Computer
using javascript, is it possible? (3) I wondering if it is possible to try and make a java script to get the computer username and log it?
/huh.gif" style="vertical-align:middle" emoid=":huh:" border="0" alt="huh.gif" /> edit Topic
title ....
Is It Possible To Create A Web Based Mmo In Javascript?
And could there be free movement without reloading the page? (4) I would like to get some information before launching myself to the JS libraries. Is it possible to
load maps or images and with the press of a button "scroll" or move the image inside some kind of
window up, down, left or right? It would be like scrolling an image sideways, upwards or downwards.
I would also like to know if multiple connections can be made and lets say there was a user
standing in the location (127, 160) of the map, would there be the possibility of loading the image
of that player? Maybe with database connections and storing their information there?....
Javascript Error
Error "missing ) in parenthetical" with JSON statment (2) Hello! I'm trying to execute following code: CODE a=new Array();
a=eval("("+responseText+")"); for (prop in a) { e=document.getElementById(prop)
if (e) {e.innerHTML=a } and I recieve error in CODE a=eval("("+responseText+")");
what's wrong? responseText it's result from php2js() function. Apache 2.2.6/PHP5.2.5/MySQL
5.0.45....
Help: Disable All Buttons Inside A Div Element
How do you write a function to disable all buttons given a div id (8) I need help to write a function to disable all buttons iside a div ID. if possible the function will
disable all buttons even the ones inside child divs belonging to the main div.....
Special Wii Javascript
New Javascript Objects for Wii (2) I found on Nintendo.com a while back some new javascript objects dealing with the Wii Remote. I
have decided to post a link to these new Javascript objects here. Wii javascript These new
Javascripts can detect whether or not a Wii Remote is enabled, the position of the pointer, and even
the tilt of the remote. It also has an object that determines the keypress of the Wii. These can be
very useful for Wii sites. Maybe have a menu load with AJAX when the remote is tilted. Add button
functionality such as when the A and B button are pressed, the form is submitted. Just....
I`m New To Javascript.
(5) Does anybody know where I can find a good site to teach me more than I already know. I know about
functions and how to set up alert scripts. I really wanna make a counter script.....
Javascript Events Not Working For Ie
(6) I just made this little html file and I used javascript to show which arrows you're pressing. It
just says the key code, but only for the arrows, so it will say "37, 38, 39, 40" if you're
pushing all the arrows. When you let go of the arrows, it won't show that value. It works
perfectly in Firefox, but I can't get it to run in Internet Explorer. The little notification
bar down in the bottom left of the window says there's an error, and it just sits there. All I
used was a function for onKeyDown and onKeyUp on the body, and every 10 milliseconds it sh....
Web Applications: J2ee Or Javascript/css/html
(1) I'm currently programming web applications using AJAX/CSS/HTML and they're pretty
cross-browser. However when I heard of this language J2EE I had second thoughts. But I ran into GWT
(Google Web Toolkit) which compiles Java code to Javascript/HTML. With this said, my mind tells me
that Java developers desire to use Javascript/HTML languages to create web applications over Java.
So, which one should I start developing web applications in? Java? or Javascript....
Hiding <div> Boxes With Javascript
Javascript Help #1 (8) This is my first help post in this Java/JavaScript section. Can someone write/find me a piece of
code that will hide boxes? Preferred stuff: There is a bar that has the subtitle of the box
contents. A button on the right side of the bar shows and hides the div box. Contents are in a box
with a border and slides in and out of the bar smoothly and relatively quickly. Box MUST be
customizable using CSS internal/external stylesheets . Any help would be appreciated. All codes
will be tested and best code be selected.....
Javascript : No Right Click Script !@
This script will allow you to protect your source coad ! (13) This script will help you to protect your source code Add this to Section of your site !
HTML var message="Function Disabled!"; /////////////////////////////////// function
clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if
(document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){
alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmoused....
What's The Relationship Between Javascript And Java
are they the same or different (7) I think most of you always confuse about java and javascript .So I make this topic to talk about it.
Javascript and Java ,they have the same first four letter. Java and Javascript is the two language
is very popular in the web world.Java is the general-purpose programming language that you can
create an application or an applet.Javascript is a script language that looks sort of like java;with
it you can do various nifty things in web pages.They are independent languages ,used for different
purposes.If you are interesting in creating a website you should learn how to w....
I'm Making My Own Javascript Only Rpg :d
earliest beta perhaps (7) Well I randomly decided to make an rpg. So far its all in javascript, and that's how I intend to
keep it. Eventually you will be able to save with a permanent cookie or by getting an encrypted
code. Right now you can only walk around and go to 2 maps. I have used preloading, and the maps load
extremely fast. But there is one problem, maybe you guys could help but I mostly just posted to tell
you guys something /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif"
/>. Well the problem is the character images load extremely slow and i know wh....
Adding Rows & Columns In Html Table Using Javascript
(4) I'm trying to create a website with a form that collects some user information to store in MySQL
database. However, I've a problem when I want to dynamically add new rows and columns in the
HTML table so that the user can add more information in the dynamically added textboxes. Here's
what I have: CODE
Quantity
unit(s)
....
One Click Copy And Paste To Clipboard
in simple Javascript (5) I've been search the web for few weeks to see if Java can do one click copy and paste function
to the clipboard and then I can just Ctrl-V the copied "texts." I initially got this idea when I
began to approve hosting application. Instead of writing the same message over and over again, I
decided to make me a page where I can simply copy the code to appropriate answers. And seems like my
laziness is the mother of inventions /laugh.gif' border='0' style='vertical-align:middle'
alt='laugh.gif' /> Instead of doing Ctrl-A, Ctrl-C then Ctrl-V to the post board I started....
Javascript Close Window
Javascript close window (19) Hi does anyone have a code to close the browser window. This code needs to be used to close an
actual full sized window, not a pop-up window.....
How Can I Resize The Web Browser?
using javascript (5) how can i resize the window with javascript, and how to center an element in the browser window?
thanks a lot!!! /blink.gif' border='0' style='vertical-align:middle' alt='blink.gif' />
Corrected title spelling. This is more appropriate in Programming section. Please, please make sure
that you post in the right section. ....
Javascript Window.open
Plz help me ,, thanks (5) When I try to run the following code in Internet Explorer I get an "Invalid argument" error but it
works fine on Firefox CODE window.open("users/ve_edit.php","edit
av","toolbar=no,location=no,directories=no,status=no,sc
rollbars=no,resizable=no,copyhistory=no,width=600, height=400"); plz help me /blink.gif'
border='0' style='vertical-align:middle' alt='blink.gif' /> ....
How To Insert Code With Javascript
How to insert into a div an amount of code (11) Hi, I have the next html page CODE function insertcode() { var code =" blablabal babala
babababab here comes header fadfafa anchor blalbababa " var myText =
document.createTextNode(code); document.getElementById("content").appendChild(myText); } -->
Insert Code This code insert the data as text. The html tags are not treated like markup.
I need to insert the code in a time. I mean i can not go tag per tag. (E.g.
document.createElement("p")... ) Is there any method to insert a pice of html code into a div and
keep it like code not like tex....
Javascript Slideshow Tutorial
How to make a slideshow in JavaScript (14) JavaScript Slideshow Tutorial I'm going to show you how to make a impressive JavaScript
slideshow. First, you're probably asking: why would I want to make a slideshow in JavaScript?
There are a number of reasons. First, you don't have to build a new HTML page for each picture.
Secondly, the page will load much faster because the of the compactness of the page. Ok let's
get started with this example. First we'll add a tag in the of our HTML document. In that
script tag we will build the following: CODE first = 1; last = 4; ....
Java Is Not Javascript; Javascript Is Not Java
(2) Java, developed under the Sun Microsystems brand, is a full-fledged object-oriented programming
language. It can be used to create standalone applications and a special type of mini application,
called an applet. Applets are downloaded as separate files to your browser alongside an HTML
document, and provide an infinite variety of added functionality to the Web site you are visiting.
The displayed results of applets can appear to be embedded in an HTML page (e.g., the scrolling
banner message that is so common on Java-enhanced sites), but the Java code arrives as a separ....
Learning Javascript.
-->What I know and a question<-- (7) How hard is it to fully learn javascript? People say it is easy, however, it looks pretty
complicated! What do I know, you ask? I know how to make a button (that I describe in another
post) so that when you click it, it generates something at random. I have the script for it here:
var quotes = ; function getQuote() { var qs = document.getElementById("quote"); var quote =
quotes quotes ; alert(quote); } Describe button here. . . . . . Original script
copyright by ROADDHOGG....
Javascript resources?
ie, a book. (10) Hi, I'm trying to learn Javascript. The thing is, I don't have any reference material
around, so I'm gonna need to buy a book or something. Are there any which you would recommend? I
looked on some websites but there are literally hundreds of books of this kind. /blink.gif"
style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> (in answer to the
below, sorry sauron, didnt see that one)....
Looking for Javascript:, Move, Blocks, Of, Div's, Around, And, Change, Child, Attributes
|
Searching Video's for Javascript:, Move, Blocks, Of, Div's, Around, And, Change, Child, Attributes
See Also,
|
advertisement
|
|