开发者

how to get the value by javascript?

HTML:

I want to pass the value from the gsearch to the q parameter. The following is the ways I make but it couldn't work. How should I do it?

action="http://test.com/search.php?q=<script type="text/javascript">document.getElementById('gsearch').value;</script>">

updated:

in my site. i want to make a google custom search: so i put the following code in the homepage. 0156290304977:8texhu0mrk the google search value. gsearch.php page which i put the google custom search code in and show the searched result

   <form method="get"  action="http://test.com/gsearch.php?cx=0156290304977:8texhu0mrk&cof=FORID:11&ie=UTF-8&q=..." >

    <input type="text" title="" value="" name="q" class="search-input" id="gsearch" />
    <input type="submit" value="" name="sa" id="search-button"/>
    </form>

now, i want to when the user input the searched text in the 开发者_运维技巧gsearch text box, if he click the submit button,. then on the gsearch.php page shows the searched result.


if you want to submit to this: http://test.com/search.php?q=theinput just do this:

   <form target="_top" method="get"  action="http://www.cnn.com/search.php" >

<input type="text" title="" value="theinput" name="q" class="search-input" id="gsearch" />
<input type="submit" value="submit" id="search-button"/>
</form>

the entire idea behind the <form> element is that it is making sure that all of the inputs from the user will be sent to the action.
the form will take the input from the q and add it to the action automatically.

so in your simple case. no manipulation is required.

Test it here http://jsfiddle.net/L4rHG/1/

this will be submitted to http://edition.cnn.com/search.php?q=theinput


Or you need over javascritpt

<script>
function SubmitForm(){
window.open("http://test.com/search.php?q="+document.getElementById('gsearch').value)
return false;
}
</script>

<form method="get"  action="http://test.com/search.php" onSubmit="SubmitForm();false" >

<input type="text" title="" value="" name="q" class="search-input" id="gsearch" />
<input type="submit" value="" name="sa" id="search-button"/>
</form>


<form action="http://test.com/search.php?q=">
<script>
document.forms[0].action += 'new_action.html';
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜