Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2008, 12:49 AM   PM User | #1
cww2
New to the CF scene

 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
cww2 is an unknown quantity at this point
Passing parameter in function

Hi - I've tried passing this hundreds of different ways without effect. In a nutshell, I have an HTML page that is generated dynamically from db and has form elements with the same name plus the numeric ID from the db tacked on the end to make the form elements individual.

With JS, I've been able to determine which form elements need to be processed. Where I'm falling short is when I try to validate those form elements, my code breaks down:


function addrsvp(str)
{
var event_id = +str;
if (Record_Validator(''+event_id+'') == true)
{
document.frm.action = "?action=addrsvp&id="+event_id
document.frm.method = "post"
document.frm.submit()
}
}


// This part works fine - with the Record_Validator, just using the alert box, I've verified "ev_id" is being passed correctly. Where it breaks down is the if statement adding the ev_id to the end of "first" - tried everything I could find:

function Record_Validator(strg)
{
var ev_id = +strg
if (document.frm.first+ev_id+.value == "")
{
alert(''+ev_id+'');
return (false);
}

return true;
}

Any suggestions will be tremendously appreciated.

Chase
cww2 is offline   Reply With Quote
Old 05-07-2008, 01:11 AM   PM User | #2
binaryWeapon
Regular Coder

 
Join Date: Sep 2007
Location: AZ, USA
Posts: 685
Thanks: 6
Thanked 46 Times in 46 Posts
binaryWeapon is on a distinguished road
Would this work at all?

Code:
function Record_Validator(strg)
{
var ev_id = +strg;
fieldname='first'+ev_id;
if (document.frm.fieldname.value == "")
{
alert(''+ev_id+'');
return (false);
}
Also: just so you know, on your alert: alert(''+ev_id+'');, you can just put alert(ev_id);, and when you call ev_id you can just put var ev_id = strg;

Last edited by binaryWeapon; 05-07-2008 at 01:13 AM.. Reason: Sidenote
binaryWeapon is offline   Reply With Quote
Old 05-07-2008, 01:20 AM   PM User | #3
cww2
New to the CF scene

 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
cww2 is an unknown quantity at this point
Quote:
Originally Posted by binaryWeapon View Post
Would this work at all?

[code]
function Record_Validator(strg)
{
var ev_id = +strg;
fieldname='first'+ev_id;
if (document.frm.fieldname.value == "")

Thanks for the overall tips. Much appreciated.

The above modification gives me the error "document.frm.fieldname.value is null or not an object"

Really appreciate the help.

Chase
cww2 is offline   Reply With Quote
Old 05-07-2008, 02:14 AM   PM User | #4
cww2
New to the CF scene

 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
cww2 is an unknown quantity at this point
BTW - with document.write - I was able to verify that "fieldname = "first"+ev_id " returned the desired fieldname. Still can't figure out integrate that to work correctly -- document.frm.fieldname.value == "" ....

Chase
cww2 is offline   Reply With Quote
Old 05-07-2008, 02:18 AM   PM User | #5
binaryWeapon
Regular Coder

 
Join Date: Sep 2007
Location: AZ, USA
Posts: 685
Thanks: 6
Thanked 46 Times in 46 Posts
binaryWeapon is on a distinguished road
OK this might not work at all, I would just suggest trying putting your javascript below your form if thats possible. I don't know why but sometimes when I had my form after my javascript it wouldn't recognize the form or the fields.

This might not be the problem, but I wanted to mention it.

GL
binaryWeapon is offline   Reply With Quote
Old 05-07-2008, 02:24 AM   PM User | #6
cww2
New to the CF scene

 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
cww2 is an unknown quantity at this point
Thanks again GL. If I hardcode it to what I know will be one of the form fields - document.frm.first6.value == "" - then all is cool and works as it should.

I guess I maybe should have thought of asking this earlier but should it make a difference that the parameter is always numeric?

Chase
cww2 is offline   Reply With Quote
Old 05-07-2008, 02:54 AM   PM User | #7
cww2
New to the CF scene

 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
cww2 is an unknown quantity at this point
Finally found something that worked:

if (document.getElementById("first" + strg).value == "")

Thanks again for all the help. You're very kind to take the time.

Chase
cww2 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:29 AM.


Advertisement
Log in to turn off these ads.