473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

JavaScript Function Debugging

Hello,
I want to click a button which sends the name of an input field to the function. From there I want the function to take the value of that input field, split it by the "/" symbol, take the last field in the array, check to see if it is already part of a different textarea field name extra_field[4], and if not, add it to the end of that field. Here is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. <form name="new_product">
  2. My input field:
  3. <input type=text name=test><button onclick="colors(test)">run colors on test</button>
  4.  
  5. <script language="JavaScript">
  6. <!--
  7. function colors(blob) {
  8.   var blob2=document.forms["new_product"].blob.value;
  9.   var blob3=blob2.split("/");
  10.   iname=blob3[(blob3.length-1)];
  11.   if(blob=="clear")    document.forms["new_product"].extra_field[4].value="";
  12.   else {
  13.     if(document.getElementById('extra_field[4]').value == "") // nothing in there
  14.       document.forms["new_product"].extra_field[4].value="runpictures:," + iname;
  15.     if(document.getElementById('extra_field[4]').value.search(iname) == "-1")//not found so add
  16.       document.forms["new_product"].extra_field[4].value=document.forms["new_product"].extra_field[4].value + "," + iname;
  17.   }
  18. }
  19.  
  20. //-->
  21. </script>
  22.  
  23. <textarea  name="extra_field[4]"></textarea>
  24. </form>
Feb 26 '07 #1
5 1575
pronerd
392 Expert 256MB
Here is what I have so far:
And...... Does it work? Does it not work? Is there an error your getting? What are you asking about?
Feb 26 '07 #2
Oops - Sorry!

FYI I have changed the code to the following after doing a bit of research:
The main difference being I have added an ID field to the test field and am now calling it be the getElementById tag.
Expand|Select|Wrap|Line Numbers
  1. <form name="new_product">
  2. My input field:
  3. <input type=text name=test id=test><button onclick="colors('test')">run colors on test</button>
  4.  
  5. <script language="JavaScript">
  6. <!--
  7. function colors(blob) {
  8.   var blob2=document.getElementById(blob).value;
  9.   var blob3=blob2.split("/");
  10.   iname=blob3[(blob3.length-1)];
  11.   if(blob=="clear")    document.forms["new_product"].extra_field[4].value="";
  12.   else {
  13.     if(document.getElementById('extra_field[4]').value == "") // nothing in there
  14.       document.forms["new_product"].extra_field[4].value="runpictures:," + iname;
  15.     if(document.getElementById('extra_field[4]').value.search(iname) == "-1")//not found so add
  16.       document.forms["new_product"].extra_field[4].value=document.forms["new_product"].extra_field[4].value + "," + iname;
  17.   }
  18. }
  19.  
  20. //-->
  21. </script>
  22.  
  23. <textarea  name="extra_field[4]"></textarea>
  24. </form>

This does not work in its current state.
I am getting the following feedback from firefox:
When I click on the
Expand|Select|Wrap|Line Numbers
  1. <button onclick="colors('test')">run colors on test</button>
button, nothing happens. I installed Firebug for Firefox and it tells me that
blob is "test"
var blob2 is undefined
var blob3 is undefined.

To following error also appears
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(blob) has no properties
  2. colors("products_image")
  3. onclick(click clientX=0, clientY=0)
  4. [Break on this error] var blob2=document.getElementById(blob).value;
  5.  
Does this help at all - let me know what else I can do to help problem solve.
Feb 26 '07 #3
acoder
16,027 Expert Mod 8TB
Your problem is with extra_field[4]. You can't have that because Javascript thinks it is an array and you are accessing the 5th element. Instead just call it extra_field.

You are using getElementById, but you have not defined an id for extra_field.

Also, you are mixing and matching between using getElementById and using forms. To avoid confusion use one - the preferred one is getElementById. For that, you will of course need an id.
Feb 27 '07 #4
Thanks everyone for the help!
I've now got a functioning code... The base of it ended up being this...

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2. <!--
  3. function colors(blob) {
  4.   var blob2=document.getElementById(blob).value;
  5.   var blob3=blob2.split("\\");
  6.  
  7.   iname=blob3[(blob3.length-1)];
  8.   if(blob=="clear")    document.getElementById('extra_field4').value="";
  9.   else {
  10.     if(document.getElementById('extra_field4').value == "") { // nothing in there
  11.       document.getElementById('extra_field4').value="runpictures:," + iname;
  12.     }
  13.     if(document.getElementById('extra_field4').value.search(iname) < 0) {//not found so add
  14.       document.getElementById('extra_field4').value=document.getElementById('extra_field4').value + "," + iname;
  15.     }
  16.   }
  17. }
  18. //-->
  19. </script>
Feb 27 '07 #5
acoder
16,027 Expert Mod 8TB
Glad you got it working.
Feb 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Tony G. | last post by:
Hi there, I have an APS 3 application, running on a Windows 2003 Web edition server - it is a very busy website, and when users are click on certain links (membership info), a new window i...
16
by: Java script Dude | last post by:
To all Mozilla JS Guru's (IE dudes welcome), I have spent the last three years developing complex DHTML applications that must work in IE 5.5sp2+ but I use Mozilla 1.3+** to do all my...
3
by: Java script Dude | last post by:
I have still yet to see a JavaScript Editor that comes close to reading a good JS book, learing it and using it with a text editor. Anyway, here my recipe for build successfull DHTML...
2
by: Chris | last post by:
Hi, I have a Javascript function that loads a page with a progress bar for long process. The progress bar is a gif animation and for some reason it the animation is stuck when the function is...
2
by: Alex Nitulescu | last post by:
I have the option 'Just in time debugging' set as CLR/Native/Script. In Project Properties/Debuggers I have ASP.NET debugging. Still, although I have breakpoints set everywhere in my javascript,...
14
by: John M | last post by:
Hello, In Microsoft Visual Studio .NET 2003, How can I debug javascript/vbscript codes (client side) ? Thanks :)
3
by: Steve Brecher | last post by:
Context: I am having a problem with the phpBB package. Currently about 0.4 on the 0-10.0 scale from utter cluelessness to wizardry with respect to PHP, I find a small debugging package at...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
4
by: paul.denlinger | last post by:
Please excuse this very basic question; I'm just starting to learn JavaScript. I have just modified added a toUpperCase statement to change strings to upper case, but it does not run. Can you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.