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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.