在同一个页面的url传递文本框的值不形于使用jQuery或JavaScript提交按钮(passin

2019-10-17 22:47发布

有没有在同一页面URL传递文本值,而不形式或提交按钮,我有什么办法javascript function ,但是这个function正在为drop down values not for text box values? 我需要在同一个页面的URL发送文本值,而不表,并提交按钮

现在这是通过在同一个页面的url此页面下拉值下拉网页,但现在我很困惑我如何发送同一页面的URL文本框的值不形或使用该JavaScript函数提交按钮?

function getComboB(sel) { 
var customers=document.getElementById("customers");
var value = sel.options[sel.selectedIndex].value;
addreceivable.action = "addreceivable.php?customers="+value+"";
addreceivable.submit();
}
<form name="addreceivable" id="addreceivable">
<select name="customers" id="customers">
<option value="Test">Test</option>
<option value="Demo">Demo</option>
<option value="Check">Check</option> 
</select>
<input type="submit" name="test" id="test" value="Submit">
</form>

现在我的问题在这里解决我已经完成了我的代码通过在同一个页面的URL文本值,而无需提交按钮使用JavaScript函数

function getComboB(sel) { 
var textbox=document.getElementById("textbox");
var input_val = document.getElementById("textbox").value;
addreceivable.action = "test2.html?textbox="+input_val+"";
addreceivable.submit();
}

<form name="addreceivable" id="addreceivable">
<input name="textbox" class="textbox" onchange="getComboB();">
</form>

感谢所有朋友!

Answer 1:

随着文本框使用.VAL()抓住它的价值。 我相信这是jQuery的,但这样你可能需要这一点。

function getTextbox() {
   var textbox = $('input.textbox').val();
   //Do what you want with textbox now
}
<input name="textbox" class="textbox">


Answer 2:

function getComboB(sel){
     //your other code
     //new code here
     var input_val = document.getElementById("id of your textbox").value;
}

您可以使用它来听在文本框中的变化:

document.getElementById("id of your textbox").addEventListener("change", getComboB);

上面一行将听取在文本框中输入,然后调用你的函数getComboB()此时你会得到你的文本框的值。



文章来源: passing textbox values on the same page url without form or submit button using jquery or javascript