English 中文(简体)
具有2个县的表格,需要根据价值确定不同功能
原标题:form with 2 buttons need to call different functions based on value

我有一页,在卢尔有许多员额数据。

For example, www.test.com/test.php?userid= tester &name=test&so on

上面一页有这样的形式:

<? 
$set=get_value_set;
if($set ==1) {
    $set_value="SET";
} else {
    $set_value="UNSET";
}

?>
<form name="test">
<input type="text" readonly="READONLY" value="<? echo $user_id; ?>">
<input type="submit" value="Email" name="submit_user">
<input type="submit" value="<? echo $set_value; ?>" name="submit_user">

<? 
function setuser()
{
//sets the value

}
function email_user()
{
//sets the value

}
?>

上面有两顿,在我点击电子邮件时,即希望将顿电子邮件的价值传递给电子邮件——用户功能,并在那里做一些预想。 在我点击了 set子时,情况类似。

NOTE:But in both cases above, I want the form to remain in the same page with the same post data in the url, but I also want the page to be refreshed so that the set button can have a value of Set or Unset depending on the database update.

这是可能的吗?

最佳回答

我将着手删除<代码>各纽特/代码>的行动,并改变这些行动。

<input type="button" class="btn-Email" value="Email" name="submit_user" />
<input type="button" class="btn-Other" value="<? echo $set_value; ?>" name="submit_user" />

那么,你可以很容易地处理每点击和提交表格。

$(function() {

  $(".btn-Email").click(function() {
    // append anything you want
    var but_email_value = $(this).val(), // or $(".btn-Email").val()
        btn_other_value = $(".btn-Other").val();

    $("form").submit();
  });

  $(".btn-Other").click(function() {
    // append anything you want
    var but_other_value = $(this).val(), // or $(".btn-Other").val();
        btn_email_value = $(".btn-Email").val();

    $("form").submit();
  });

});
问题回答

更改 传真

<form id="test" name="test">
...
<button onclick="email_user();">Email</button>
<button onclick="setuser();"><? echo $set_value; ?></button>
</form>

您的职责应为:

document.getElementById("test").submit();




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签