Solved

using <a> tag to submit my form

Posted on 2006-11-09
9
229 Views
Last Modified: 2012-08-14
Hi
i have looked up a way of submitting a form using javascript and tried to implement it into a test page.

I can t seem to get it working, i may be missing somthing very obvious. I am new to javascript and have only just started putting together my own scripts.

Whenever i test the script on my apache server i get errors on page in my browser status bit.

Here is my code

            <tr >
            <td  width="330px" height="35px"><div class="jobtitle"><p><?php echo $position; ?></p></div></td>
            
            <td  width="135px">
            <div class="jobbuttons">
            <form action="jobs_edit.php" name="edit" method="post">
            <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
            <a href="javascript:void(0)" onClick="document.edit.submit(); return false;">Edit Job</a>
            </form>
            </div>
            </td>
            
            <td  width="135px">
            <div class="jobbuttons">
            <form action="$_SERVER['PHP_SELF']" name="delete" method="post">
            <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
            <a href="javascript:void(0)" onClick="document.delete.submit(); return false;">Delete Job</a>
            </form>
            </div>
            </td>
            </tr>

thanks

-s-



0
Comment
Question by:socross
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 100 total points
ID: 17910298
Some names are reserved words.
Take beter something not so regualr like "delete"
Like this:

<table>
          <tr >
          <td  width="330px" height="35px"><div class="jobtitle"><p><?php echo $position; ?></p></div></td>
         
          <td  width="135px">
          <div class="jobbuttons">
          <form action="jobs_edit.php" name="xedit" method="post">
          <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
          <a href="javascript:void(0)" onClick="document.xedit.submit(); return false;">Edit Job</a>
          </form>
          </div>
          </td>
         
          <td  width="135px">
          <div class="jobbuttons">
          <form action="$_SERVER['PHP_SELF']" name="xdelete" method="post">
          <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
          <a href="javascript:void(0)" onClick="document.xdelete.submit(); return false;">Delete Job</a>
          </form>
          </div>
          </td>
          </tr>
</table>

0
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17910303
socross,
delete may just be a keyword.
Just rename that form so:
This works:
          <form action="$_SERVER['PHP_SELF']" name="del" method="post">
          <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
          <a href="javascript:void(0)" onClick="document.del.submit(); return false;">Delete Job</a>
          </form>
D
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17910323
socross,

I can probably help you with this but I don't see why you need javascript.  I would just use php and create a "custom" link.  You wouldn't need a form, input or javascript.  An example of what I mean is below.  Let me know if you want to stick with Javascript.

          <tr >
          <td  width="330px" height="35px"><div class="jobtitle"><p><?php echo $position; ?></p></div></td>
         
          <td  width="135px">
          <div class="jobbuttons">
          <a href="jobs_edit.php?jobID=<?php echo $jobID; ?>">Edit Job</a>
          </div>
          </td>
         
          <td  width="135px">
          <div class="jobbuttons">
          <a href="$_SERVER['PHP_SELF']?jobID="$jobID">Delete Job</a>
          </div>
          </td>
          </tr>

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17910331
I see that you have some good help on using javascript and the form.  I forgot to mention that if you use my method you may need to change from using POST to GET to get the name/value pairs in the querystring.

bol
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:socross
ID: 17910485
b0lsc0tt
The method you suggested is the method i used before but i want to keep the links clean and use POST, I will go back to that if i cant get this working.

WIth regards the javascript method i still get the errors even after replacing the delete with del.

any other suggestions

-s-
0
 
LVL 10

Assisted Solution

by:iamanindian
iamanindian earned 100 total points
ID: 17911441
How abt this:

------------------------------------------------------------------------------------------------------------------------------------
          <div class="jobbuttons">
          <form action="jobs_edit.php" name="edit" method="post">
          <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
          <a href="javascript:void(0)" onClick="document.edit.submit(); return false;">Edit Job</a>
          </form>
          </div>
          </td>
         
          <td  width="135px">
          <div class="jobbuttons">
          <form action="$_SERVER['PHP_SELF']" name="f_delete" method="post">
          <input type="hidden" name="jobID" value="<?php echo $jobID; ?>">
          <a href="javascript:void(0)" onClick="document.forms['f_delete'].submit(); return false;">Delete Job</a>
          </form>
          </div>
------------------------------------------------------------------------------------------------------------------------------------

Regards
WC
0
 
LVL 10

Accepted Solution

by:
dennis_maeder earned 100 total points
ID: 17911882
If your error condition persists after renaming the second form, then the problem is not in the js.
I get no errors - just a failed page on clicking the links, but that is to be expected as the urls are specific to your system. That leaves the php which is flawed:
          <form action="$_SERVER['PHP_SELF']" name="delete" method="post">
should be
          <form action="<?php $_SERVER['PHP_SELF']?>" name="delete" method="post">
and it is worth checking that $jobID contains a correct value.
:D
0
 
LVL 1

Author Comment

by:socross
ID: 17913425
Thanks for spoting the php error, was spending to much time blaming the javascript and not thinking straight, tested it in a static page and all worked fine.

The reason i was getting errors on the server was that i was generating a many of these forms (foreach job ID) so i was just creating duplicates of the forms.
So just needed to give each form a unique name (using the jobID) and all works fine.

Its always the obvious thing that i seem to miss.

Im definately starting to apprciate javascript a bit more, seems to have a solution for everything.

Does anyone know any good tutorial sites?


Thanks for all your help

-s-
0
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17913840
socross,

For reference you might bookmark these:
  http://developer.mozilla.org/en/docs/JavaScript
  http://en.wikipedia.org/wiki/JavaScript_syntax
  http://www.w3schools.com/jsref/

Always glad to be of assistance...

D
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now