1

I want add value in jquery function an post it to my php file. I call my jquery function whit onclick event but i don't know how can add value. I have this input tag:

 <input type="hidden" name="code" id="code" value="<?php echo $code; ?>"  />

and my onlick event this is:

<span onClick="previewed_files(); checkDb();">start</span>

and my checkDb function it is:

    <script type="text/javascript" >

    function checkDb(adscode){
        $.post('myphp.php',{adscode: adscode},function(data){
            $('#mydiv').html(data);}

                        );
            }
  </script>

now I can't call value from input by id code in my checkDb() function in onclick event. please help me. thank you

2
  • You call checkDb() with no parameters, so "adscode" is undefined when the function is executed. Assuming your code (in $code) does not contain single or double quotes, I'd try <span onClick="previewed_files(); checkDb('<?php echo $code; ?>');">start</span> Commented Aug 26, 2014 at 17:53
  • I'm using this code but not work Commented Aug 26, 2014 at 18:04

2 Answers 2

1

Here :

<script type="text/javascript" >
function checkDb(adscode){
    $.post('myphp.php',{adscode: adscode, value: $('#code').val()},function(data){
        $('#mydiv').html(data);});
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

work for me : JSFiddle and RequestBin
0

You must check for ajax tutorials to get value in php. You cant get parameter value in function untill you pass in the function.

to get value of hidden variable -

var value = jQuery('#code').val();

Now, you can use this variable in your funciton.

1 Comment

thank you I add your code in my function now how can use this variable? sorry I don't know jquery well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.