Hi,
Here's my form:
http://www.steinrogan.com/SecureSite_v2_beta/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 2538
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);
-
}
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_beta/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
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,...
|
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.
...
|
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) {...
|
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...
|
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
}
...
|
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...
|
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...
|
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...
|
by: johnjsforum |
last post by:
Buddies,
I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function
////////////////////////////////////////////////////////////////////////////////////...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |