Solved

using <a> tag to submit my form

Posted on 2006-11-09
9
228 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:socross
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now