Jump to content

Get Form Textbox data on the fly


richie19rich77

Recommended Posts

Hi All,

Been using PHP for about 2 weeks now; and I am able to get along, but I have hit a brick wall on how to solve this problem and would like some hints.

I have created a form with a textbox within side a table, this textbox will be used to enter in data but I want to check that data before it is POSTed back to the server. I have created the code below that uses javascript to change the textbox colour on "onMouseOut", and was wondering if I could grab the textbox text as well at the same time ?

If I could grab the text I could then do some checking on it and change the textbox colour to green to signal correct data has been entered.

Also is there also any way in PHP to recreate the code below, becuase as yet I haven't found one.

Thanks

(I have taken out the script tags as this message wouldn't post with them in)

[code]
<!--
function change(color){
var el=event.srcElement
if (el.tagName=="INPUT"&&el.type=="text")
event.srcElement.style.backgroundColor=color
}
//-->


<FORM onMouseOut="change('#75CFFC')" METHOD=POST>
  <table width="100" border="3">
    <tr>
    <tr>
      <td><input name="richard4" type="text" class="TextBox"></td>
    </tr>
  </table>

</form>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/28154-get-form-textbox-data-on-the-fly/
Share on other sites

PHP runs on the server.

It generates the page which then runs in the client browser.

Javascript is running in the browser.

PHP cannot, therefore, know what the mouse, or anything else, is doing on the client PC.
Thanks for the reply, I shouldn't have been so lazy and posted in the 1st place. 

I have made this code up just for testing, better suited to the javascript section, but your coments have helped me understand what the limits are in PHP and javascript.

Thanks

[code]
<!--
function testResults (form) {
var el=event.srcElement
if (el.tagName=="INPUT"&&el.type=="text")
event.srcElement.style.backgroundColor='#75CFFC'

    var TestVar = form.inputbox1.value;
    alert ("You typed: " + TestVar);
}
//-->

<FORM NAME="myform" ACTION="" METHOD="GET">Enter something in the box: <BR>
<INPUT TYPE="text" NAME="inputbox1" onMouseOut="testResults(this.form)" VALUE=""><P></td>
</form>

[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.