Solved

Issues with following javascript

Posted on 2013-06-13
3
238 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 55

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

860 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