Hello i am using javascript to pass variable to another php file but its working with KeyUp function ... i want to use variable value instead of keyup ..(like value from $_GET[] or some other variable) here is my code

<html xmlns="http://www.w3.org/1999/xhtml">
<head> 

<script type="text/javascript" src="js/jquery.js"></script>

<script type="text/javascript" >
$(document).ready(function(){
$('#op_comp_id').load('bh.php').show();

    $('#get_value_id').keyup(function() {
    $.post('bh.php', { id: form.get_value.value },
        function(result){
            $('#op_comp_id').html(result).show();
            });  
    });

});
</script>

</head> 
<body> 
<?$id = $_GET['id'];?>
<form  name="form">
<input type="text" id="get_value_id" name="get_value" value="<?php echo $id ?>"></input>
</form>

<div id="op_comp_id"></div> 


</body> 
</html>

* Edited *

This will pass variable Value to my bh.php in post mode (bh.php?id=value) .... so any alternative to keyup in this case ??? so i dont have to put keyup... value should go through variable ...

share|improve this question
2  
can you rephrase your question? – slash197 Jun 18 '12 at 6:45
didn't get what you want to do ?? you want to pass the text box value on php page with different jquery event ?? – hRaval Jun 18 '12 at 6:46
@hRaval Yes the the url should be bh.php?id=value – Harinder Jun 18 '12 at 6:49
If you will use keyup event after every keypress for letter ajax will be called. You can also use blur event. – VibhaJ Jun 18 '12 at 6:50
I have edit the post ... to make it more clear... – Harinder Jun 18 '12 at 6:53

1 Answer

When you pass the value from text box , user can fill the text box with many possible way , so use following method to pass to php

 $(input[name=get_value]).bind('keyup click blur focus change paste',function(){ 
                var id = $(this).val();
                $.ajax({    
                    type: "POST",                                  
                    url: "bh.php",
                    async: false,
                    data: "clientId="+id ,
                    success:function(response){
                    $('#op_comp_id').html(response).show();

                    }                        
                });
               } 

bh.php use following code

<?php
 $id = $_REQUEST['clientId'];
 // your code
?>
share|improve this answer
Thx for reply ... is there a way i can use it in hidden field of form ... where value comes from variable`<input type="hidden" id="get_value_id" name="get_value" value="<?$echo $id?>"></input>` – Harinder Jun 18 '12 at 7:23
@Harinder yes you can , simple don't use id , use "name"$(input[name=textboxname])" so you can use in any textbox , and there is no need"</input>" tag – hRaval Jun 18 '12 at 7:25
thx ...but dont get u this time can u please edit post to it get clear to me thx – Harinder Jun 18 '12 at 7:30
edited , now try this – hRaval Jun 18 '12 at 7:50
:( not getting any output ... – Harinder Jun 18 '12 at 8:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.