Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

form action="self"

Posted on 2006-07-20
13
41,492 Views
Last Modified: 2011-08-18
what does the "action="self"  attribute do?  I'm assuming it repost the the webpage and/or the form?

                        <form id="q1" action="self">
                              <div><p>Score is the measure of a learner's <input type="text" name="answer" maxlength="15" size="15"    onclick="enableSubmit()" />.</p><br /><br /></div>
                              <div><input type="reset" name="reset" value="Reset" />
                              <input type="button" name="submit" value="Submit" onclick="checkQuestion(q1);" /></div>
                        </form>
0
Comment
Question by:Mike Johnson
  • 3
  • 3
  • 3
  • +3
13 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 125 total points
ID: 17147016
Hi uksub,

i normally use "", but yes, it means it posts to itself, so if the page the form sits in is called "Page1.asp", by using self or "" you are telling the form that the action is Page1.asp

Apresto
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 17149200
No, action="self" means the form will be submitted to a page named "self" in the current directory.

For instance, if your current url is http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_21926063.html
The form will be submitted to http://www.experts-exchange.com/Web/Web_Languages/HTML/self

If the page does not exist, then you'll get an error404.

Your form uses javascript and javascript is able to modify the form's action before the data is submitted.  This means that your form might work when javascript is enabled even if the "self" page does not exist.

In your case, submitting the form's data is probably not necessary.  Your javascript probably checks if the answer is correct on the client side.  In that case, the value of the "action" attribute does not matter since the data is never submitted.

For your form not to submit the data, have the form's "onsubmit" return false.

In any case, the code you posted can be improved... you should use the "onsubmit" event of the form element and you should not need to use the onclick event on your input/text element.  Also, you should not need to have a <div> AND a <p> as container... that's redundant.  And use padding/margin to modify the spacing instead of <br>.

Assuming the answer is checked on the client side, the final code should look like this:

                    <form id="q1" action="dummy" onsubmit="checkQuestion(this); return false;">
                         <p>Score is the measure of a learner's <input type="text" name="answer" maxlength="15" size="15" />.</p>
                         <input type="reset" name="reset" value="Reset" />
                         <input type="button" name="submit" value="Submit" />
                    </form>

The checkQuestion() function should use the DOM to get the content of the "answer" and probably display some message like "nope, that's wrong" or "yes, that's correct".
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 17149994
perhaps you mean:  target="self"  -- which is a shortcut way of assigning the target to the current frame.  So if your form page is in a frame called "MyFrame", then the two tags below are functionally the same:

<FORM name="myform" action="mypage.html" target="self" >

<FORM name="myform" action="mypage.html" target="MyFrame" >
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Mike Johnson
ID: 17150496
I'm not referring to "traget"...  "apresto" seems to have the idea i'm referring to.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 17151088
Allow me to repeat that action="self" does NOT submit the data to the current url.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 17151923
To hook in to what GrandSchtroumpf has already said...

target="self" tries to load a page called "self" (extentionless) whereas
target="_self" would submit the data to the current URL

So with target="self" you'll likely get... "Page not found" ;)

Regards,
Max.
0
 
LVL 2

Expert Comment

by:cyberal_
ID: 17221596
The attribute "target" and "action" are totally different.

<form action="self" target="self"> would send the data to a page named "self" (www.example.com/self, probably generating a 404 error) using a window or frame named "self" (if it doesn't exist a new window is openned).

<form action="" target="_self"> (notice it's "_self", not "self") would send the data to the same page u are currently on (www.example.com/current_page.php or whatever, not generating a 404) using the same window or frame your form is located.

Some people have already said this, but maybe this way is clearer.

gl every1
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 17270697
uksub, you are supposed to accept the correct answers, not the wrong answers.
0
 

Author Comment

by:Mike Johnson
ID: 17279289
Thanks "cyberal".... that's what I was looking for,  "<form action="" target="_self"> ".
0
 
LVL 23

Expert Comment

by:apresto
ID: 17279325
uksub - please make a request to community support to reallocate the points to the correct answer, or to reopen the thread so that you can do so, Thanks
 
Apresto
0
 
LVL 2

Expert Comment

by:cyberal_
ID: 17280423
You're welcome, uksub
0
 

Author Comment

by:Mike Johnson
ID: 17286851
apresto.... how do i  make a "rquest to community support to reallocate the points"?
0
 
LVL 23

Expert Comment

by:apresto
ID: 17287194
Click on support, second link at the top of the page, and just post a question with a link to this question and ask them to reopen the question so you can accept the correct answer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

791 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