viewing the form variables that are being submitted

Y

yawnmoth

<form action="">
<input type="submit" name="a" value="Submit">
<input type="submit" name="b" value="Save">
</form>

<script>
function zzz() {
var vars = '', e = this.elements;
for (i=0;i<e.length;i++)
vars+= e.name + '=' + e.value + '&';
alert(vars);
}

for(i=0;f=document.forms;i++)
f.onsubmit=zzz;
</script>

If you hit either submit button you'll get an alert box with
"a=Submit&b=Save&" in it. The resultant URL, however, will only have
one of them set. ie. "b=Save" or "a=Submit" but not both.

My question is... is it possible, in javascript, to view not what
form elements exist but what form variables will be submitted?

My goal is to adapt this into a bookmarklet that I can use on
arbitrary websites.
 
J

Jeremy J Starcher

On Fri, 01 May 2009 12:02:32 -0700, yawnmoth wrote:

[ Form and code snipped ]
My question is... is it possible, in javascript, to view not what form
elements exist but what form variables will be submitted?

My goal is to adapt this into a bookmarklet that I can use on arbitrary
websites.

You might want to try reading this:

http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/
e4859563aabaf768/dec455c027d3154c?q=serialize+form&lnk=ol&
 
S

SAM

Le 5/1/09 9:02 PM, yawnmoth a écrit :
<form action="">
<input type="submit" name="a" value="Submit">
<input type="submit" name="b" value="Save">
</form>

<script>
function zzz() {
var vars = '', e = this.elements;
for (i=0;i<e.length;i++)
vars+= e.name + '=' + e.value + '&';
alert(vars);
}

for(i=0;f=document.forms;i++)
f.onsubmit=zzz;
</script>

If you hit either submit button you'll get an alert box with
"a=Submit&b=Save&" in it. The resultant URL, however, will only have
one of them set. ie. "b=Save" or "a=Submit" but not both.


Usually both (or all) submit buttons have same name, and it is the sent
value that gives the information about which one was clicked.
My question is... is it possible, in javascript, to view not what
form elements exist but what form variables will be submitted?

I think no.

Except
My goal is to adapt this into a bookmarklet that I can use on
arbitrary websites.

With which navigator ?
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top