Jump to content

Archived

This topic is now archived and is closed to further replies.

rajmohan

i want to get value from textfield without clicking button or link???? (HELP ME)

Recommended Posts

I want to get the value from one text field without clicking the button or link from it

whether it is possible or not ??

Help me i dont know but it is required now for my project.

Share this post


Link to post
Share on other sites
JavaScript event listener

// mozilla

el.addEventListener("event_to_monitor", function_to_fire_when_event_is_triggered, false);

event_to_monitor => (ie: keyup, onmouseover, ...)

[url=http://developer.mozilla.org/en/docs/DOM:element.addEventListener]http://developer.mozilla.org/en/docs/DOM:element.addEventListener[/url]

me!

Share this post


Link to post
Share on other sites
[code]
<?php
if(file_exists('path/to/file') ){
  fopen('path/to/file', filesize('path/to/file');
  $file = fread('path/to/file');
} else {
  echo "Cannot locate file.";
}
?>
[/code]

Just put something like that in the beginning of the script your running?

Share this post


Link to post
Share on other sites
No guys,

I am having a value in text field which is from javascript

example

var a_value = document.form1.ac.value;  // i pass value
var service_value = document.form1.service.value; // this also i am passing
document.form1.searchval.value = amc_value+','+service_value;

here i text field serchval got value now, i  should be take this value to my query without clicking the button or link


Share this post


Link to post
Share on other sites
Yea I completely read your post wrong sorry.

As for what you're trying to do I'm unsure how to go about it.

Share this post


Link to post
Share on other sites
[quote author=rajmohan link=topic=109403.msg440866#msg440866 date=1159190438]
No guys,

I am having a value in text field which is from javascript

example

var a_value = document.form1.ac.value;  // i pass value
var service_value = document.form1.service.value; // this also i am passing
document.form1.searchval.value = amc_value+','+service_value;

here i text field serchval got value now, i  should be take this value to my query without clicking the button or link
[/quote]

so... how is your form being submitted? you've got to have some sort of trigger event signaling your value to be added to your query. at the very least, you could set a timer to trigger every few seconds and grab the value, but that's not very efficient at all. if you're simply wanting to do it when the form is submitted, run your function during the "onsubmit" attribute of the form itself.

Share this post


Link to post
Share on other sites
I think a JS timer would fix your problem.

<code>
timerID = 0;
timerID = setTimeout("UpdateTimerFunc()", 1000);

function UpdateTimerFunc()
{
    // Do whatever you need to do here.
}
</code>

It's the closes you'll get to actively monitoring a form field, as far as I know.

Share this post


Link to post
Share on other sites
i assume you are typing in a textfield and want it to query db once you have finished typing ? If so you should head over to the ajax forum with the attribute onchange=" " in your mind.

Share this post


Link to post
Share on other sites
yes you are correct i want after getting the value in textfield it should be taken to my query execution??

This is what i needed it will be very helpful.

You told that ajax will be helpful but i dont have any idea about that one please is there any option


Share this post


Link to post
Share on other sites
AJAX is not too hard, requires some javascript and a backend query script.
Move to this forum section -> http://www.phpfreaks.com/forums/index.php/board,51.0.html <- and ask the spesific question and i'm sure someone will show you an example and help you on the way.

Share this post


Link to post
Share on other sites
if you're running the query after every keystroke, instead of using onchange for a text field or textarea, you'll be better off using the onkeyup.

Share this post


Link to post
Share on other sites
[quote author=businessman332211 link=topic=109403.msg441687#msg441687 date=1159280718]
onfucus, onblur then all you have to do is click in the field to get the value.
[/quote]

how will that help? if you do an onfocus, you only get the value when you initially focus on the field which will be empty when you start. then, onblur, you'll have to focus away from the field, and if you're doing that, you might as well have a button or link to grab it anyway... ???

Share this post


Link to post
Share on other sites
i am asking without clicking the button are link (reason the page should not refresh)
i want ot get the value from the textfield. after receiving the values from javascript

Share this post


Link to post
Share on other sites
I would have thought that with both onkeyup and onchange that every time the user types another letter it will query the database using ajax. I think it will be a hard thing to do without making the server do extra work, unless the user is typing in something that is the same length then you could check if after the user gets above that lenght.

If you think about it how will the form know when the user is getting to the end of what they are typing it will have to enter in the database every time they press a key. If you use the onblur method the user will still have to click else where on the form or press the tab. I think what you are trying to do isn't really possible. I would like to hear if you do manage to do it and how you have gone about it.

Good luck

Share this post


Link to post
Share on other sites
sorry misread the first post. Thought you wanted to put it into a database. If you are only getting the value out ignore what I have said above. Perhaps you can put it to a $_SESSION value. Rewriting this everytime would be as bad as the database thing above, (don't know where I got the idea you wanted to do that).

Anyway you still need Ajax

Share this post


Link to post
Share on other sites
onchange responds only if the field value is changed and at the time you take the focus away from the field again, not while typing.

Share this post


Link to post
Share on other sites

×

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.