Hi,
Here's my form:
http://www.steinrogan. com/SecureSite_v2_b eta/addthis.php
When I add two or more Dependant Items and remove one that's not the last that I added, I won't be able to remove any more Dependant Items. Say I deleted the first Dependant Item and try to remove the second Dependant Item - it will try to look for the link inactive.html that should never be accessed.
I believe the problem is with reassigning the onclick attribue values. I spent the whole day yesterday on this, but can't figure out what I'm doing wrong.
Any help is greatly appreciated,
Thank you!
Csanád
8 2565
Hi,
I have the following function. Everything works except the assignment of the onclick event on line 20. I need to pass 3 arguments dynamically to the function call like this: rmdep(this, i, d). How do I go about this?
Thanks for your time,
Csanád - function rmdep(what,i,d)
-
{ // i is the index of current Item
-
// d is the index of current Dependant Item
-
var deps=document.getElementById('dep_'+i).value; // deps is the number of Dependant Items for current Item
-
if (d==deps) // remove the last Dependant Item
-
{
-
deps--;
-
document.getElementById('dep_'+i).value=deps;
-
}
-
else // remove Dependant Item from the middle of list; renumber following Dependant Items
-
{
-
var q=d+1;
-
var depup;
-
for (q; q<=deps; q++)
-
{
-
depup=document.getElementById(i+'_'+q);
-
depup.setAttribute('name','f'+i+'_'+d);
-
depup.setAttribute('id',i+'_'+d);
-
depup.previousSibling.previousSibling.firstChild.nodeValue='Dependant Item ['+d+']';
-
depup.nextSibling.nextSibling.onclick='rmdep(this,i,d); return false';
-
depup.nextSibling.nextSibling.setAttribute('id','r_'+i+'_'+d);
-
d++;
-
}
-
deps--;
-
document.getElementById('dep_'+i).value=deps;
-
}
-
while (what && what.tagName!='DIV') { what=what.parentNode; }
-
if (what) what.parentNode.removeChild(what);
-
}
acoder 16,027
Recognized Expert Moderator MVP
Try: - depup.nextSibling.nextSibling.onclick='rmdep('+this+','+i+','+d+'); return false;';
Thanks Acoder! Your help is greatly appreciated, but something is still not quite right with my code and it's driving me crazy! :)
You can check it out here:
http://www.steinrogan. com/SecureSite_v2_b eta/addthis.php
Please do the following:
- add 4 Dependant Items,
- remove the second Dependant Item (the idea here is that Dependant Items [3] and [4] get renumbered to [2] and [3], respectively)
- try removing the very first Dependant Item.
This is where the code crashes. I believe the trouble is coming from the "this" keyword's reassignment, but I'm not sure.
Any ideas?
Thanks very much!!
Csanád
Try: - depup.nextSibling.nextSibling.onclick='rmdep('+this+','+i+','+d+'); return false;';
It will work fine if you write....... - depup.nextSibling.nextSibling.setAttribute('onclick','rmdep(,'+i+','+d+'); return false;');
this needs not to be appended, but you have to append i and d these are the JavaScript Variables.
I hope it will work fine.
And all the best with your try.
Kind regards,
Dmjpro.
The problem is gone. :) Thank you so much for your help Acoder and Dmjpro!!
All the best!
Cheers,
Csanád
acoder 16,027
Recognized Expert Moderator MVP
Glad you got it working. So how exactly did you get it working?
Glad you got it working. So how exactly did you get it working?
Truth be told, I don't know. :) All I did was that I deleted all the alerts from the function that were there to help me find the bug...and shushhh, with that, everything worked like a charm. In other words, the error I described earlier could not be reproduced. It's still a mystery. But it's working, so I'm happy!
Thank you again for your help!
Cheers,
Csanád
It will work fine if you write....... - depup.nextSibling.nextSibling.setAttribute('onclick','rmdep(,'+i+','+d+'); return false;');
this needs not to be appended, but you have to append i and d these are the JavaScript Variables.
I hope it will work fine.
And all the best with your try.
Kind regards,
Dmjpro.
I did a mistake here.....!! - depup.nextSibling.nextSibling.setAttribute('onclick','rmdep(this,'+i+','+d+'); return false;');
Kind regards,
Dmjpro.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Free-Ed, Ltd. |
last post by:
I am going nuts trying to find a paragraph in a book that described how to
change the text content (HTML) in a DIV.
Actually I have an array of HTML strings that I want to drop into the DIV,
depending on button clicks, etc.
Putting this stuff into TEXTAREA and TEXT is simple, but I want to be able
to mix font families, weights, sizes, and stuff like that.
Thanks for your help.
|
by: Pavils Jurjans |
last post by:
Hallo,
I have been programming for restricted environments where Internet Explorer
is a standard, so I haven't stumbled upon this problem until now, when I
need to write a DOM-compatible code.
The question is about best practices for passing parameters to an event
function.
I have, say, the following HTML:
|
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {
document.images.src = eval("mt" +menu+ ".src")
}
alert("imgOff_hidemenu");
hideMenu=setTimeout('Hide(menu,num)',500);
|
by: Adi |
last post by:
Okay, this issue has been annoying me for a little while now.
I need it to work on Mozilla 1.6 & IE 6
This is what I would like to be able to do:
var row = document.createElement("TR");
var tdImage = document.createElement("TD");
var img = document.createElement("IMG");
img.src = "results.gif";
var theA = document.createElement("A");
|
by: RobG |
last post by:
I am trying to dynamically add an onclick to an element,
however I just can't get the syntax right. consider the
following function:
function doClick (evt,x) {
// do things with evt and x
}
Which is called statically by:
<button onclick="doClick(event,this);">Click me</button>
| |
by: RobG |
last post by:
I have a function whose parameter is a reference the element that called it:
function someFunction(el)
{
...
}
The function is assigned to the onclick event of some elements in the
HTML source:
|
by: Bonzo |
last post by:
>From within a function, I want to pass a/some parameters to another
function, AND all arguments, passed into this function.
e.g.
function firstFunction(){
//this function may have been passed, 0, 1, or n arguments...
...
//call another function...
var someCalculatedValue = 'someValue';
|
by: zholthran |
last post by:
Hi folks,
after reading several threads on this issue (-> subject) I fear that I
got a problem that cannot easily be solved by the offered workarounds
in an acceptable way, at least not with my limited c & c++ experience.
Maybe some of you can help.
the problem:
I need several instances of a class whose (non-static!) methods should
serve as callbacks for a dll (which can' be manipulated/adapted in any
|
by: johnjsforum |
last post by:
Buddies,
I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function
//////////////////////////////////////////////////////////////////////////////////// version 1 : using global variables //////////////////////////////////////////////////////////////////
var _textField, _divColorPicker; // global vars
window.onload = function()
{
_textField = document.getElementById('htxaMessage'); // fill...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |