Solved

Issues with following javascript

Posted on 2013-06-13
3
237 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 54

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

803 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