Javascript - concatenate field value to onclick button link? - Stack Overflow

I have an issue I need to fix on an existing app that I didn't initially write. Here is a snippet

I have an issue I need to fix on an existing app that I didn't initially write. Here is a snippet of code that doesn't do what it is intended to do. What it is supposed to do is take the value of the field and upon clicking "Search", append that to the redirection to pass in the querystring to the destination page:

<form name="frm_someform">
    <input type="text" name="f_date" id="f_date"/>
    <input type="button" value="Search" onclick="parent.location='runreport.asp?date=' + document.frm_someform.elements['f_date'].value); + '"/>
</form>

Now, as you javascript folks can plainly see, the concatenation doesn't work. I've searched high and low for how to properly concatenate, but something isn't translating correctly (in my head). Note that if I take out the concatenation, the redirection works fine, so there is something with that causing the issue. Yes, of course in the example above, I could simply make the form submit the proper value with a real 'submit' button, but I have whittled the code down here for simplicity - it is much more plex than the example I have above.

(*Note, I successfully tested concatenation through other javascript functions, but the possibility exists that the purely inline code must be different)

Thanks in advance, Beems

I have an issue I need to fix on an existing app that I didn't initially write. Here is a snippet of code that doesn't do what it is intended to do. What it is supposed to do is take the value of the field and upon clicking "Search", append that to the redirection to pass in the querystring to the destination page:

<form name="frm_someform">
    <input type="text" name="f_date" id="f_date"/>
    <input type="button" value="Search" onclick="parent.location='runreport.asp?date=' + document.frm_someform.elements['f_date'].value); + '"/>
</form>

Now, as you javascript folks can plainly see, the concatenation doesn't work. I've searched high and low for how to properly concatenate, but something isn't translating correctly (in my head). Note that if I take out the concatenation, the redirection works fine, so there is something with that causing the issue. Yes, of course in the example above, I could simply make the form submit the proper value with a real 'submit' button, but I have whittled the code down here for simplicity - it is much more plex than the example I have above.

(*Note, I successfully tested concatenation through other javascript functions, but the possibility exists that the purely inline code must be different)

Thanks in advance, Beems

Share Improve this question asked Nov 14, 2012 at 23:54 BeemsBeems 8102 gold badges16 silver badges36 bronze badges 4
  • What happens when you try and output the document.frm_someform.elements['f_date'].value) in a browser developer console? (Say using console.log()?) Does it return the correct/expected value? – Fergus In London Commented Nov 14, 2012 at 23:58
  • 1 parent.location = 'runreport.asp?date=' + document.frm_someform.elements['f_date'].value); + ' What is parent? Why is there a closing parenthesis? Why is there a + and a ' after the semicolon? – m02ph3u5 Commented Nov 14, 2012 at 23:58
  • Fred cleaned it up for me. I had a number of extra non-necessary (and potentially detrimental) characters following the collection of the field value. – Beems Commented Nov 15, 2012 at 0:07
  • marabutt - I covered that above in the ments below the code block – Beems Commented Nov 15, 2012 at 0:08
Add a ment  | 

1 Answer 1

Reset to default 5

Please, try this:

<form name="frm_someform">
    <input type="text" name="f_date" id="f_date"/>
    <input type="button" value="Search" onclick="parent.location='runreport.asp?date='+ document.getElementById('f_date').value"/>
</form>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745075123a4609787.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信