1

I Have a select button in php code which Passes the Dynamic generated Row value and How do i do this jquery?

PHP code

<input type ="button"  onclick="select(add,'<?php echo $_POST['somevale=ue']?>')"

Javascript

function select (fnname, val){
   //Val changes every time
}

How do i acheive the same in Jquery in Putting the click event to the button and passing the Dynamic value and Defining the Function in Jquery?

2 Answers 2

1

Use the click handler inside your document ready. Note that add must be a valid function for this to work available in the current scope.

$(function() {
    $('input').click(function() {
        select(add, 'value you need to pass');
    });

    function add() {
        ..
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

I have to pass the Value Dynamically From php there i have to bind the onclick event such as, <input type"button" onclick ="select('add','<?php echo $myvalue')"> // In The jquery Function I should be able to take that value and Do manipulations
@Someone - Where is the value coming from in your PHP code, and where is going in the JavaScript code? A little more explanation of the HTML structure will be helpful.
1

You can use HTML5 data-attributes here (they don't cause issues in HTML4), like this:

<input type="button" class="add" data-value="<?php echo $_POST['somevalue']?>" />

Then you can fetch it in your function using .attr(), like this:

$(function() {
  $(".add").click(function() {
    var value = $(this).attr("data-value");
    select('add', value); //call original function
    //or, put that function's content in here
  });
});

Give it a try here

5 Comments

Thanks for your quick response Iam Having the buttons generated for each row in the table dynamically How Do I get Each Button data values
@Someone: If you just do data-value=".$something." when you're generating, $something being the variable that's changing every row, that's all you need...the jQuery above gets the data-value from the clicked element.
hi I have 5 rows But Iam Getting For First Row "Select button" and If i click on next row "Select Button" Iam Not getting for the remaining rows
Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks Really Thanks .I got it working with Class name and After getting the class name with attribute Vale I was Able to differentiate with the buttons
@Someone: Welcome really :) Be sure to accept answers to this and future questions via the check-mark beside the question that helped :)

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.