0

i want to get this number "1" in my javascript function, how can i do it?

HTML--» onclick="displayResult(1)

Javascript --»

function displayResult(obj)
{ 
var number = ??????;
}

And after i get the number i wanted to be available in PHP. like this:

    function displayResult(obj)
{
 var number = ??????;
<?
$sql = mysql_query("SELECT * FROM `artigos` WHERE id = ????var number????");
$resultado = mysql_fetch_array($sql); 
?>
}

It is possible to do it like this ?

Effect needed --» http://youtu.be/Jz-7Vrx-Xaw

1
  • And what did you tried? How about to output data from your PHP to your js? Commented Aug 12, 2013 at 8:53

2 Answers 2

2
onclick="displayResult('1')"
function displayResult(obj)
{ 
document.location.href='xyz.php?st='+obj;
}
//now in your php page
$sql = mysql_query("SELECT * FROM `artigos` WHERE id = '".$_REQUEST['st']."'");
Sign up to request clarification or add additional context in comments.

1 Comment

I can't refresh the page i will lost my info.
1

onclick callthis function with your value, this javascript function will call the some.php file using jquery ajax call.you can find how to use jquery ajax from jquery site.

javascript side

function displayResult(obj)
{ 
    var number = ??????;
    $.ajax({
    type: "POST",
    url: "some.php",
    data: { name: obj}
    }).done(function( msg ) {
    alert( "Data Saved: " + msg );
    });
}

PHP side some.php

<?php
    $number = $_REQUEST['name'];
    echo $number;
    $sql = mysql_query("SELECT * FROM `artigos` WHERE id = ????var number????");
    $resultado = mysql_fetch_array($sql); 
?>

now you can use your values sent from js file in some.php $number.

3 Comments

This is the page that i am doing right now : teste.solucoes.pt/jstabela/index4.php and when i press the add button the should Data be filled in table without refresh the page and i am not using forms to do it, just a <a> link with onclick(function)
what you want, explain clearly, the above code also you can use for your need, just echo your result in php and again you can get it in js using ajax response now you have the response in js, so you can updated html with js now
This is the effect that i want: youtu.be/Jz-7Vrx-Xaw it can be done with this method??

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.