开发者

jquery, replace html on submit

I have a form which is using a select list to jump around my site. This is currently using onclick window.location so user selects the page and presses go and it goes to that开发者_运维技巧 page.

I now need to add a small text box for the user to type in a code (say 123456) and then when they click go, it should go to the url selected, but with the [CODE] being the number entered in the box. I discovered jquery replaceAll so it gave me the idea to have this in the select html:

http ://jumptothispage.com/parts/p[CODE]/edit

http ://jumptothispage.com/jobs/j[CODE]/edit

When you press go, it would replace all [CODE] in that html with the code entered and then jump to that page selected, e.g.

http ://jumptothispage.com/parts/p123456/edit

http ://jumptothispage.com/jobs/j123456/edit

I am already using jquery on my site so makes sense to try and utilize that again. I'd appreciate a pointer and or other suggestions instead.

Thanks, Paul.


A workaround: Store the code in a cookie, so at least it's not visible to every person who looks at the URL bar. Then in every onclick, fit it into the URL to send the user to the "right" page.

Or, have your select option's value literally read CODE, which your onclick interprets to mean "The user hasn't set the code yet." When the user types in the code, store it in a variable (in the example below, realcode), and you can then do this:

$('select#navigation option').each(function(idx, el) {
    $(el).attr('value', $(el).attr('value').replace(/CODE/, realcode));
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜