Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    get value of sumbit button

    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?

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    What's the problem? The code you've provided (should) work, not unless you haven't set your submit button's name to mysubmit.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    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">

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Because it's erroneous. You might mean this instead:
    Code:
    var form = document.forms[0];
    alert(document.forms[0].mysubmit[0].value);
    alert(document.forms[0].mysubmit[1].value);
    ...or alternatively, you could use:
    Code:
    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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Quote Originally Posted by esthera View Post
    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).
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #7
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    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

  • #8
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Quote Originally Posted by esthera View Post
    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

    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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •