?
Solved

Issues with following javascript

Posted on 2013-06-13
3
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

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 16

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 16

Author Closing Comment

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

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
Suggested Courses

764 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