Jump to content

Set variable from textbox


MockY

Recommended Posts

I do an Ajax call when the user tabs out of a text box using onblur(). It works just fine but I need to pass along variable values that have yet been set.

To show what I mean:

<input type="text" name="comment[]" onblur="loadurl('ajax.php?update_record=<?php echo $r['Id']; ?>&comment=')" />

The loadurl() function fires the Ajax call and will do it's thing. Problem is, I want the comment variable to have the value of whatever the user types in the box before the user leaves the box. All the script now has to work with is the Id of that specific record.

 

My thought was to add a javascript variable that will get the same value as what the user types using onkeyup or similar but don't know how to do it

 

Any help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/281931-set-variable-from-textbox/
Share on other sites

However, this got me thinking about making it a little trickier. I should probably start a new thread, but it so closly related to this question

 

What if I had 2 text fields, and I wanted to fetch the value from the second text box as well. Since I can't use this.value as I'm not fetching value for the active box, what would I use instead. I tried the following, but that did not work.

onblur="loadurl('ajax.php?update_record=<?php echo $r['Id']; ?>&net=' + encodeURIComponent(this.value)) + '&comment=' + document.getElementById('comment').value"

EDIT: Removing document. made it work

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.