Solved

using <a> tag to submit my form

Posted on 2006-11-09
9
231 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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
 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

777 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