richie19rich77 Posted November 22, 2006 Share Posted November 22, 2006 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.srcElementif (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 More sharing options...
Barand Posted November 22, 2006 Share Posted November 22, 2006 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. Link to comment https://forums.phpfreaks.com/topic/28154-get-form-textbox-data-on-the-fly/#findComment-128788 Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 AAAH! JAVASCRIPT *runs away* Link to comment https://forums.phpfreaks.com/topic/28154-get-form-textbox-data-on-the-fly/#findComment-128792 Share on other sites More sharing options...
mb81 Posted November 22, 2006 Share Posted November 22, 2006 As stated above, this can only be done by javascript and I would recommend an onChange on the input box, not an onMouseOut on the form. Link to comment https://forums.phpfreaks.com/topic/28154-get-form-textbox-data-on-the-fly/#findComment-128794 Share on other sites More sharing options...
richie19rich77 Posted November 22, 2006 Author Share Posted November 22, 2006 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] Link to comment https://forums.phpfreaks.com/topic/28154-get-form-textbox-data-on-the-fly/#findComment-128797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.