Jump to content

Set variable from textbox


MockY
Go to solution Solved by kicken,

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.

Edited by MockY
Link to comment
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

Edited by MockY
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.