Monday, December 12, 2011

How to create an html or php form that submits to current page?

I am trying to create a simple html or php form that does the following: User enters input in input box, user hits submit button, whatever was in the input box prints on the same page next to the input box. Thanks.How to create an html or php form that submits to current page?
You could do it with both Javascript (client-side) and PHP (server-side). It is easy to do with both. Currently, I have not PHP installed on my machine. I can write a simple demo in Javascript.



---- Demo: Cut the following text and paste it to a page (.htm). Then double click it to view it in IE. Then test it.



Tested with IE8 and FireFox 3.6





%26lt;html%26gt;

%26lt;head%26gt;

%26lt;title%26gt;Writing To Self%26lt;/title%26gt;



%26lt;script type=';text/javascript';%26gt;

function WriteText ()

{

var textInput = document.getElementById (';myText';);

var diplay = document.getElementById (';display';);

display.innerHTML = textInput.value;

}

%26lt;/script%26gt;



%26lt;/head%26gt;

%26lt;body%26gt;

%26lt;form method=';get'; action=';WriteToSelf.htm';%26gt;

%26lt;input type=';text'; id=';myText'; /%26gt;

%26lt;span id=';display';%26gt;%26lt;/span%26gt;

%26lt;p%26gt;聽%26lt;/p%26gt;

%26lt;input type=';button'; value=';Apply'; onclick=';WriteText()'; /%26gt;

%26lt;/form%26gt;

%26lt;/body%26gt;

%26lt;/html%26gt;

No comments:

Post a Comment