2014-02-26 64 views
-2

我有一個顯示值的php頁面。我想使用超鏈接而不是按鈕。我想要發生的是,用戶將更新文本框中的值,然後單擊「開始」。我的問題是我不知道如何使用超鏈接傳遞文本框的值。有人能幫幫我嗎?HTML:如何使用超鏈接傳遞文本框的值?

謝謝所有。

例如:

<form action="" method= "post"> 
First name :<input type="text" name ="fname"/>" 
    <a href="" onclick="return confirm('Do you really want to update information?')">Update</a> 
</form> 
+0

你想張貼在點擊'hyperlink' – Girish

+4

'form'爲什麼要使用一個鏈接,而不是提交?這沒有意義。 – Bryan

回答

0

更改您的形式是:

<form action="" method= "post"> 
    First name :<input type="text" name ="fname"/>" 
    <input type="submit" value="Update"/> 
</form> 

並使用CSS來顯示輸入作爲超鏈接

form input[type="submit"] { 
    background: none; 
    border: none; 
    color: blue; 
    text-decoration: underline; 
    cursor: pointer; 
} 

你也可以使用JavaScript有<a>提交表格,我認爲這種方式雖然更容易。

0

如果您確實想使用超鏈接,您需要在JavaScript中調用FormElement的submit()方法來提交沒有常規提交按鈕的表單。

例如,從MDN documentation

document.forms["myform"].submit() 

如果你想要做這一切在你的onclick處理器(這通常被認爲是不好的做法),那麼你可以給你<form>id並稱之爲一次全部像這樣:

<a href="#" onclick="confirm('Do you really want to update information?')&&document.getElementById('myform').submit()"> 
    Update 
</a> 

但是,它可能是最好的一個提交按鈕,堅持以提供更好的瀏覽器/客戶的支持和更語義正確。如果你想讓按鈕看起來像一個鏈接,最好使用CSS來使它看起來像你想要的樣子。

0

這可能是有用的:

<form action="test.php" id="myForm" method= "post" onsubmit="if(confirm('Do you really want to update information?')) {this.submit();}"> 
First name :<input type="text" name ="fname" id="fname"/> 
    <a href="javascript:void();" onclick="document.getElementById('myForm').onsubmit();">Update</a> 
</form> 
相關問題