...

View Full Version : get value of sumbit button



esthera
06-25-2008, 08:46 AM
I want to do different validation based on the value of the submit button

I tried

var form = document.forms[0];
alert(document.forms[0].mysubmit.value);

so that i can see the value but i'm just getting undefined
what am i doing wrong?

rangana
06-25-2008, 09:00 AM
What's the problem? The code you've provided (should) work, not unless you haven't set your submit button's name to mysubmit.

esthera
06-25-2008, 09:03 AM
it doesn't work

my submit buttons are
<input id="submit" type="submit" name="mysubmit" value="Next Page">
<input id="submit" type="submit" name="mysubmit" value="Prev Page">

rangana
06-25-2008, 09:09 AM
Because it's erroneous. You might mean this instead:


var form = document.forms[0];
alert(document.forms[0].mysubmit[0].value);
alert(document.forms[0].mysubmit[1].value);


...or alternatively, you could use:


var form = document.forms[0]; // I wonder what's the use of this in your code
var submit=document.getElementsByTagName('input');
for(var i=0;i<submit.length;i++)
{
if(submit[i].type=='submit')
{
alert(submit[i].value);
}
}
}


Hope it helps.

esthera
06-25-2008, 09:31 AM
i changed them not to be name=submit

and did

var form = document.forms[0];
alert(form.submit.value);
but it still undefined.
what can i be doing wrong?

rangana
06-25-2008, 09:36 AM
i changed them not to be name=submit

and did

var form = document.forms[0];
alert(form.submit.value);
but it still undefined.
what can i be doing wrong?

You change what? Show us your complete modification instead.

Also, what made you decide on changing the name? The post I've given earlier had been tested and should have worked....or it's giving you an error?

You confused me (i'm always at this state).

esthera
06-25-2008, 11:30 AM
i'm not clear - how can i get the value of the submit button
I only want to do validation if it's next page and not if it's previous page

rangana
06-25-2008, 11:39 AM
i'm not clear - how can i get the value of the submit button
I only want to do validation if it's next page and not if it's previous page

Yes you are'nt :rolleyes:

What validation? You never mentioned anything about it earlier in your post?
I don't know if i'm taking this right, but I'm lost to what your (real) problem is.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum