How do I pass variables (to the same page) using a custom javascript submit button?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: How do I pass variables (to the same page) using a custom javascript submit button?

  1. #1
    Join Date
    Apr 2005
    Posts
    1

    Question How do I pass variables (to the same page) using a custom javascript submit button?

    I simply wish to pass variables (to the same page) using a custom javascript submit button.

    I've broken down my code to the basics. This is what I am working with.

    Code:
    <form method="GET" action="form.html" name="form">
    
    Name: <input name="yourname" type="text" value="">
    
    <input name="Submit" type="submit" value="Submit">
    
    <a href="form.html" onclick="javascript:document.form.submit();">Submit</a>
    
    </form>
    I can see (with use of the GET method) that the variables pass with the regular "input" button but not with the javascript button.

    Can someone explain why the values fail to pass with the custom button and offer me an alternative method or a fix?

    Thank You,

    Serpent330

  2. #2
    Join Date
    Aug 2004
    Posts
    64
    You are getting the methods of using javascript in a link mixed up.

    Try this:
    Code:
    <a href="javascript:document.form.submit();">Submit</a>
    or this:
    Code:
    <span onclick="document.form.submit();">Submit</span>
    I'm also not sure about the way you reference the form element. It might work the way it is, but if not try giving the form an id (like id="Form1") and using onclick="document.getElementById('Form1').submit();"

  3. #3
    Join Date
    Apr 2005
    Location
    Pasig, Phil.
    Posts
    8
    if your going to click on the <input name="Submit" type="submit" value="Submit"> button your variable will pass on your form.html just fine. However if your going to use a hyperlink you have to identify the variable that you would like to pass on. And it doesnt matter if your button is javascript or not.

    Code:
    <a href="form.html?var=yourname" onclick="javascript:document.form.submit();">Submit</a>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center