Javascript losing values

A

Alec Dwyer

Hello all.

The developer who usually handles my javascript has been unresponsive
in a time when I need to figure out a problem so I'm hoping for help
understanding why values are not being passed.

My form looks like the following:

< form id="mylogin_page" action="mylogin_page_check.htm" method="post"< script type="text/javascript" >
$('checkout_nav').getElements('.cart_buttons').each( function(item)
{item.setStyle('display', 'block');});
< /script >
< input type="text" name="color" value="Green" />
< a onclick="myloginfunction('submit_login');" >
< img src="/icon.png" alt="Login Now" />
Submit
< /a >
< /form >

The javascript function "myloginfunction" looks like this:

function myloginfunction(step){
if(step=='start')..................



else if(step=='submit_login'){

cartpost=$('mylogin_page');
new Request.HTML({
url: 'mylogin_page_check.htm',
method: 'post',
update: 'mycart',
onComplete: function(){
},
onSuccess: function(){
return false;
}
}).post(mycartpost);
}

What I need to happen is the html control "color" on the form needs to
be passed to the page "mylogin_page_check.htm"... which it is
currently not doing"

I went to use a js alert just after the above else if to display
values getting passed to the function... but don't know js well enough
to specify what var values need to be in the dialog to display what is
being passed.

Any help with this would be greatly appreciated.

Thank you.

--Rick
 
G

Gregor Kofler

Am 2011-02-08 14:07, Alec Dwyer meinte:
Hello all.

The developer who usually handles my javascript has been unresponsive
in a time when I need to figure out a problem so I'm hoping for help
understanding why values are not being passed.

My form looks like the following:

< form id="mylogin_page" action="mylogin_page_check.htm" method="post"
< script type="text/javascript" >
$('checkout_nav').getElements('.cart_buttons').each( function(item)
{item.setStyle('display', 'block');});
< /script >
< input type="text" name="color" value="Green" />
< a onclick="myloginfunction('submit_login');" >
< img src="/icon.png" alt="Login Now" />
Submit
< /a >
< /form >

The javascript function "myloginfunction" looks like this:

function myloginfunction(step){
if(step=='start')..................



else if(step=='submit_login'){

cartpost=$('mylogin_page');
new Request.HTML({
url: 'mylogin_page_check.htm',
method: 'post',
update: 'mycart',
onComplete: function(){
},
onSuccess: function(){
return false;
}
}).post(mycartpost);

mycartpost seems to carry the payload. However, your code snippets don't
show where mycartpost gets filled (or I haven't spotted it yet). In
addition you use some sort of library, which makes everything guesswork.
cartpost *could* be the payload (and mycartpost a typo)...

Better provide a link.

Gregor
 
A

Alec Dwyer

Am 2011-02-08 14:07, Alec Dwyer meinte:














mycartpost seems to carry the payload. However, your code snippets don't
show where mycartpost gets filled (or I haven't spotted it yet). (and mycartpost a typo)...


Yes, it is a typo... it should be mycartpost. If I do a
alert(mycartpost) I get a dialog box with the following:

[object HTMLFormElement]

How do I get the dialog box to display "green" instead? One step
further, how do I pass the value "green" off to:
url: 'mylogin_page_check.htm',

Thanks for any help.

--Rick
 
T

Thomas 'PointedEars' Lahn

Understanding is a three-edged sword.

Post real code first.

Post real *and* properly indented code.
mycartpost seems to carry the payload. However, your code snippets don't
show where mycartpost gets filled (or I haven't spotted it yet). (and
mycartpost a typo)...
^^^^^^^^^^^
Yes, it is a typo... it should be mycartpost. ^^^^^^^^^^^
Pardon?

If I do a alert(mycartpost) I get a dialog box with the following:

[object HTMLFormElement]

So `mycartpost' is a reference to the FORM element object. This is
unsurprising, isn't it?
How do I get the dialog box to display "green" instead?
window.alert("green");

One step further, how do I pass the value "green" off to:
url: 'mylogin_page_check.htm',

A) You don't.
B) <input type="text" name="color" value="green" />

<http://www.catb.org/~esr/faqs/smart-questions.html>


PointedEars
 
D

Denis McMahon

How do I get the dialog box to display "green" instead? One step
further, how do I pass the value "green" off to:
url: 'mylogin_page_check.htm',

What form processing is mylogin_page_check.htm doing with the post data
it receives? How does it refer to and use the form element "color" that
is passed to it?

A pure html page can't handle form data. It needs some sort of server
side scripting embedded in it to do that, and normally (but not always)
you'd be calling a file of a script type (eg php, aspx, pl etc) or
something in cgi-bin, to do the processing, although you might be using
an html file with embedded script commands of some flavour.

Rgds

Denis McMahon
 
S

S.T.

This is Mootools, which I don't know very well, but I think $ for that
library is just an alias of getElementById which would leave you with a
chunk of the DOM and seems like a strange thing to try and pass via POST
later on. Although maybe Mootools does something fancy I'm not aware of.

Try changing that line to:

mycartpost=$('mylogin_page').getElements('input[name=color]').get('value');

I believe that will set mycartpost the the value of your <input
name="color"> field and your alert(mycartpost) would work as you wish.

.... if the above worked, perhaps change that last line to:
}).post('color='+mycartpost);

That looks to be the format Mootools uses to pass data.
 
D

Dr J R Stockton

In comp.lang.javascript message <016e1c67-2bc7-4eeb-a354-11f2dc3f2efe@w2
1g2000yqm.googlegroups.com>, Tue, 8 Feb 2011 06:03:48, Alec Dwyer
Yes, it is a typo... it should be mycartpost. If I do a
alert(mycartpost) I get a dialog box with the following:

[object HTMLFormElement]

If you read <http://www.merlyn.demon.co.uk/js-props.htm> you ought to
be able to see how, by INCLUDEing a copy of a certain file, and
inserting one function call, you can generate a Form which allows
inspection of elements on the page in a browser-independent manner and
at a controllable size (ISTM that Chrome may include that; but as it
does so in unreadably small writing it would not help me).

And if you cannot see how to use it, and can explain where the problem
is, I can try to improve the explanation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top