Solved

Issues with following javascript

Posted on 2013-06-13
3
236 Views
Last Modified: 2013-06-18
Hi, working on a custom Project, i had encountered jquery, altough all good and working fine, but it needs to be converted in basic javascript, so i am not too good in javascript, so Please guide me here what i am missing

Jquery Code:

[u]This i have changed [/u]
 [b]onclick="removetext(this.parentNode);"[/b]
[u]before it was like below [/u]
[b] onclick="removetext($(this).parent());"[/b]
removetext = function(par)
{
	var strremove=par.text();
	var strexist = document.getElementById("projectIDS").value;
	strremove = strremove.replace(" X","");
	tempRemove(strexist, strremove);
	par.remove();
	var cproj;
		if(document.getElementById("countProj").value.length == 0)
			cproj=0;
		else
		 {cproj=parseInt(document.getElementById('countProj').value);
		 
		cproj=parseInt(cproj)-1;}						
		document.getElementById("countProj").value =cproj; 	 
}

function tempRemove(strexist,strremove)
{
	var b = strexist.indexOf(strremove);
	var after = strexist.indexOf(",",b);
	var newstrexist;
	var before = strexist.lastIndexOf(",",b);
	if(after!=-1)
	{newstrexist=strexist.replace(strremove+',',"");}
	else if(before!=-1)
	{newstrexist=strexist.replace(','+strremove,"");}
	else
	{newstrexist= strexist.replace(strremove,"");}

	document.getElementById("projectIDS").value=newstrexist;
}

Open in new window

0
Comment
  • 2
3 Comments
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 39243782
And the issues are ?

Please give us enough info so we don't have to guess what the problem is - what are you expecting your code to do, what is it actually doing / not doing - what error messages (if any) are being displayed.

Also, if I understand you correctly, you are changing from JQuery to plain JS - why as a matter of interest?
0
 
LVL 15

Accepted Solution

by:
Gurpreet Singh Randhawa earned 0 total points
ID: 39243965
I m facing issues here

var strremove=par.text();

strremove = strremove.replace(" X","");
      tempRemove(strexist, strremove);

and function tempRemove

it breaks on the first line so probably i am guessing the bottom two that it will fail here too.
0
 
LVL 15

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39255645
solved convert text() to innerHTML and it worked
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
angular2 2 way binding on load 7 39
Don't understand jquery promises 6 38
Apply tab index in forms 6 36
Change javascript css 1 21
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now