javascript - redirect to a page on a button click without submitting a form in PHP - Stack Overflow

I am trying to redirect my page to a location (addparty.php?edit=true&id=1) with a button click. I

I am trying to redirect my page to a location (addparty.php?edit=true&id=1) with a button click. I am using JavaScript for a static value. Here is the code:

Here is my PHP code and JavaScript function.

$result=mysql_query("SELECT * FROM party ORDER BY partyName");
echo mysql_error();
while($note = mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td><label>$note[partyId]</label></td>";
  echo "<td><label>$note[partyName]</label></td>";
  echo "<td><label>$note[partyAddress]</label></td>";
  echo "<td><label>$note[partyBankAcc]</label></td>";
  echo "<td><label>$note[partyBankName]</label></td>";
  echo "<td><label>$note[partyRTGSCode]</label></td>";
  echo "<td><label>$note[partyEmail]</label></td>";
  echo '<td><button name="change" id="change" value="$note[partyId]" 
                    onClick="check();">Edit</button>
  echo "</tr>";
}

Javascript code:

function check()
{
    window.location.href="addparty.php?edit=true&id=1";
}

Here I am getting all the values from party table. I want to got to addparty.php?edit=true&id=$note[partyId].If you see the onClick event it calls check() function. Now my id=1 is static and it works, but I want that id=$note[partyId] (which is unique party id of each party).

Any suggestions? Thanks in advance.

I am trying to redirect my page to a location (addparty.php?edit=true&id=1) with a button click. I am using JavaScript for a static value. Here is the code:

Here is my PHP code and JavaScript function.

$result=mysql_query("SELECT * FROM party ORDER BY partyName");
echo mysql_error();
while($note = mysql_fetch_array($result))
{
  echo "<tr>";
  echo "<td><label>$note[partyId]</label></td>";
  echo "<td><label>$note[partyName]</label></td>";
  echo "<td><label>$note[partyAddress]</label></td>";
  echo "<td><label>$note[partyBankAcc]</label></td>";
  echo "<td><label>$note[partyBankName]</label></td>";
  echo "<td><label>$note[partyRTGSCode]</label></td>";
  echo "<td><label>$note[partyEmail]</label></td>";
  echo '<td><button name="change" id="change" value="$note[partyId]" 
                    onClick="check();">Edit</button>
  echo "</tr>";
}

Javascript code:

function check()
{
    window.location.href="addparty.php?edit=true&id=1";
}

Here I am getting all the values from party table. I want to got to addparty.php?edit=true&id=$note[partyId].If you see the onClick event it calls check() function. Now my id=1 is static and it works, but I want that id=$note[partyId] (which is unique party id of each party).

Any suggestions? Thanks in advance.

Share Improve this question edited Feb 8, 2019 at 13:04 Sofyan Thayf 1,3282 gold badges15 silver badges26 bronze badges asked Mar 29, 2013 at 18:06 ashah142ashah142 5801 gold badge5 silver badges12 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Change the button to this:

echo '<td><button name="change" id="change" onClick="check(' . $note['partyId'].');">Edit</button>';

Change javascript to this:

function check(id)
{
    window.location.href="addparty.php?edit=true&id=" + id;
}

Try adding $note[partyId] as a parameter to your check() -

function check(partyId)
{
    window.location.href="addparty.php?edit=true&id="+partyid;
}

and

echo '<td><button name="change" id="change" onClick="check('.$note['partyId'].');">Edit</button>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745205425a4616571.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信