2014-03-27 33 views
0

我是HTML新手。我想要在html中完成以下操作。如何鏈接html表單和定位標記

if(link is clicked) { 
    process one form tag 
} 
else { 
    some other form tag 
} 

     this is my form tag . 
     <form name="input" action="abc.pl" method="get" id="sel"> 
     <input type="checkbox" name="vehicle" value="Bike">I have a bike<br> 
     <input type="checkbox" name="vehicle" value="Car">I have a car 
     </form> 

我想一個鏈接,例如,如果我點擊上面的表格輸入(我指的複選框值)應採取和鏈接應該處理的動作與另一名.pl文件...

+0

你說的 「過程」 是什麼意思?你想有條件地提交表格嗎? –

+0

是@UmairHafeez – user3095218

+1

[如何通過單擊鏈接提交JavaScript表單](http://stackoverflow.com/questions/6799533/how-to-submit-a-form-with-javascript-by點擊鏈接) –

回答

0

我想你可以嘗試在用戶通過使用jQuery點擊鏈接時動態改變表單動作。下面是一個簡單的例子:

HTML

<form id="form1" action="http://jimmy.right-pet.cc/test.php" method="post"> 
    <legend>Test</legend> 
    <fieldset> 
    <label for="name">Name</label> 
    <input type="text" name="name" id="name"/> 
    <input id="submit-btn" type="submit" value="submit"/> 
    </fieldset> 
</form> 
<a id="link" href="#">change form action link</a> 

JS

<script> 
    $(function(){ 
    $("#link").click(function(){ 
     $("#form1").attr("action","http://jimmy.right-pet.cc/test2.php"); 
    }); 
    }); 
</script> 

,並嘗試使用瀏覽器的開發工具來檢查,如果你點擊該鏈接後,表單操作改變。

這是jsFiddle demo

希望它有幫助。

+0

)在我的表格選項卡中,我有一個複選框列表,這些複選框作爲下一頁的輸入,這裏如果點擊鏈接,我應該將相同的輸入複選框傳遞給其他頁面 – user3095218

+0

你可以提供一個例子(jsfiddle或jsbin)嗎?你可以嘗試用純html代碼來表示你的問題(沒有python代碼) – Chickenrice

+0

請現在檢查。我有一個複選框列表,這些複選框作爲下一頁的輸入,如果點擊鏈接,我應該將相同的輸入複選框傳遞給其他頁面。 – user3095218

0

不嚴格地回答問題,但仍然是解決問題的方法。

從評論:

不要那樣做。提交給一個服務器端的URI。用提交按鈕來做。查看錶單數據中提交按鈕的值以確定要在服務器上運行的代碼分支。 - 昆汀1小時前

@Quentin請給我一個例子。我是新來的HTML

在HTML中。

<form name="input" action="abc.pl" method="get" id="sel"> 
    <label> 
     <input type="checkbox" name="vehicle" value="Bike"> 
     I have a bike 
    </label> 

    <label> 
     <input type="checkbox" name="vehicle" value="Car"> 
     I have a car 
    </label> 

    <input type="submit" name="sub" value="Some Action"> 
    <input type="submit" name="sub" value="Some Other Action"> 
</form> 

然後在abc.pl

use strict; 
use warnings; 
use CGI; 

my $c = CGI->new; 
my $sub = $c->param('sub'); 

unless ($c) { 
    # No submit value was detected so either perform a default 
    # action or return an error 
    exit; 
} 

if ($c eq "Some Action") { 
    # Do one thing 
} elseif ($c eq "Some Other Action") { 
    # Do another thing 
} 
+0

但我必須運行文件abc.pl,如果我按someaction並運行xyz.pl,如果我按其他操作「使用相同的輸入複選框值」... – user3095218

+0

以不同方式構建您的邏輯。製作'abc.pl'和'xyz.pl'模塊並從'the_one_true_form_handler.pl'調用它們。 – Quentin

+0

可以請你給我一個這樣的例子。 – user3095218