Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] Help | What is wrong with my code? (Function)


[SOLVED] Help | What is wrong with my code? (Function)

Reply
  #1 (permalink)  
Old 04-10-09, 09:45 AM
zippoxer zippoxer is offline
Newbie Coder
 
Join Date: Dec 2008
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Help | What is wrong with my code? (Function)

The next code, isn't working - a function which will configure few variables (onclick) and insert them to a function.

Code:
function defineVars() {
var ca1=document.getElementById('c1').value;
var cb2=document.getElementById('c2').value;
var cc3=document.getElementById('c3').value; 
var cd4=document.getElementById('c4').value;
var ce5=document.getElementById('c5').value;
var cf6=document.getElementById('c6').value;
var cg7=document.getElementById('c7').value;
var ch8=document.getElementById('c8').value;
var ci9=document.getElementById('c9').value;
var cj10=document.getElementById('c10').value;
showUser(ca1, cb2, cc3, cd4, ce5, cf6, cg7, ch8, ci9, cj10);
}
The code only works when I delete the ".value" from the variables.
The elements (Text boxes) that the javascript search for are placed on the same page.
The javascript code just gets the value of the elements and assign a variable for it.
Then the variables are inserted into a function (Which will launch ajax code).
if I change the function to this:
showUser('ca1', 'cb2', 'cc3', 'cd4', 'ce5', 'cf6', 'cg7', 'ch8', 'ci9', 'cj10');
(not variables used)
and I remove the variables from the code, it works perfectly.

Thanks for helpers

Last edited by zippoxer; 04-10-09 at 09:48 AM.
Reply With Quote
  #2 (permalink)  
Old 04-10-09, 02:04 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
When do you call defineVars? Because you have to wait for the document to load before it will work.

(And they definitely have ID's as well as names right?)
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Reply With Quote
  #3 (permalink)  
Old 04-10-09, 03:43 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
It's essential to paste the complete code in situations like this, and almost all others as well.
Nobody can tell you exactly what's wrong if all they can do is guess.

Since you say it works if you change the call to showUser('ca1', 'cb2', 'cc3', 'cd4', 'ce5', 'cf6', 'cg7', 'ch8', 'ci9', 'cj10'); I'm guessing the showUser function has its own way of getting a reference to the elements you need. It's possible that the showUser function accepts either an element id, or a direct reference (and is able to act accordingly) since you say it works if you remove the .value parts.

And if "it works when I do X", why don't you just do X?
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.

Last edited by TwoD; 04-10-09 at 03:46 PM.
Reply With Quote
  #4 (permalink)  
Old 04-10-09, 03:58 PM
zippoxer zippoxer is offline
Newbie Coder
 
Join Date: Dec 2008
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
FOUND THE PROBLEM.
You are right, I was needed to post the whole page.

Some of the elements that the Javascript searched for, aren't exists on the page.
I didn't knew it will damage the code!

Sorry for spending your time, and thanks.

Last edited by zippoxer; 04-10-09 at 04:04 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP inside JavaScript? pikaz JavaScript 20 07-10-10 12:55 AM
Broswer Compatability involving a WYSIWYG Editor NomadMan JavaScript 1 08-18-07 03:20 PM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Object Oriented Programming Stefan PHP 29 12-30-03 11:22 AM


All times are GMT -5. The time now is 11:50 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.