• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

using <a> tag to submit my form

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
socross
Asked:
socross
  • 3
  • 2
  • 2
  • +2
3 Solutions
 
ZvonkoSystems architectCommented:
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
 
Dennis MaederCommented:
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
 
b0lsc0ttCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
b0lsc0ttCommented:
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
 
socrossAuthor Commented:
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
 
iamanindianCommented:
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
 
Dennis MaederCommented:
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
 
socrossAuthor Commented:
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
 
Dennis MaederCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now