Log in

View Full Version : Simple onblur event script



jdadwilson
11-29-2013, 07:02 AM
I preface this post by stating that I know almost absolutely nothing about javascript.

I am in need of a simple javascript for the onblur event of a text box that will pass the value of the text box to the php script that contains the text box.

Maybe there is another way... This is what I need to do.

I have a module form that consists of multiple input boxes used to enter/edit records of a database table. Also included in the module is key information from a list of selected records. At present the user scrolls through the list of records and selects one from the list. Upon selection the page reloads with the information loaded into the input boxes for editing.

I would like to add a feature that allows the user to enter a record ID in an input box and then when the onblur event fires reload the page with the information of the entered record.

TIA

jdadwilson

djr33
11-29-2013, 07:13 AM
< [element] onblur="myfunction(this.value);">

Now you just need to define myfunction() to send the information to PHP.


function myfunction(t) {
ajaxSend(t,'http://.....page.php');
}

Then you'll need to define ajaxSend() using any number of possible ajax scripts. You could send the value as POST, GET, etc.

Does that generally make sense? Any tutorial on Ajax should give you the rest of the info you need.

jdadwilson
11-29-2013, 04:34 PM
< [element] onblur="myfunction(this.value);">

Now you just need to define myfunction() to send the information to PHP.


function myfunction(t) {
ajaxSend(t,'http://.....page.php');
}

Then you'll need to define ajaxSend() using any number of possible ajax scripts. You could send the value as POST, GET, etc.

Does that generally make sense? Any tutorial on Ajax should give you the rest of the info you need.


I guess I am now more confused... If I am using PHP why should I call an ajax script?

djr33
11-29-2013, 05:20 PM
Javascript cannot interact directly with PHP. That's what AJAX is for. You should read a tutorial about AJAX and come back with more specific questions. (I don't mean to sound dismissive, but you need to understand the basics of how this works.)

jdadwilson
11-29-2013, 09:14 PM
Javascript cannot interact directly with PHP. That's what AJAX is for. You should read a tutorial about AJAX and come back with more specific questions. (I don't mean to sound dismissive, but you need to understand the basics of how this works.)

Thanks for the info. Don't worry about sounding dismissive. Although I am old, I still need to learn new tricks. Thanks...

jdadwilson

jdadwilson
11-29-2013, 10:00 PM
Thanks for the info. Don't worry about sounding dismissive. Although I am old, I still need to learn new tricks. Thanks...

jdadwilson

OK, I am starting to get my brain around the issue. Sorry for any misunderstanding.

What I need to do is simply send a parameter (the text in the input onblur box) back to the script containing the onblur input box. Something similar to:


<input onblur="enterID('<?php $_SERVER['SCRIPT_NAME'] . "?load="?>this.value');" />

This works for selecting a table row with an onclick event since the value passed is preset and not dependent on this.value.


<tr onclick="selectRow('myScript.php?mov=11');">

This is the function...


function selectRow(theUrl) { document.location.href = theUrl; }

In this case the mov number is set when the table is built, not at runtime as needed for the onblur.

The event is firing and my code is processing the request, it is just that the $_GET value is 'this.value' not the actual value.

Again, TIA for your assistance

jdadwilson