I have this working in all browser except IE. Why does it not work?
Here is the site
The form code is here:
<FORM name ="frontpagequestion">
<input class="" type="text" name="questiontitle" value="ask your question and press enter" onfocus="if(this.value == 'ask your question and press enter') {this.value = '';}" onblur="if (this.value == '') {this.value = 'ask your question and press enter';}" size = "100">
<input type="submit" style="position: absolute; left: -9999px" onClick="process();return false">
</FORM>
The Javascript code is here:
function process(){
var title = document.frontpagequestion.questiontitle.value;
开发者_开发问答 title = escape(title);
$.cookie("INPUTBOX",title);
window.location = "/questions/ask";
}
In IE - it just returns to the main form and does not submit the inputbox value.
Any idea?
The right call to change the URL is window.location.href = "[url]", AFAIK.
Simply because IE doesn't execute the onClick event on the submit button. If you tab to it from the question box it works as expected.
You should try the onSubmit event for the <form> tag. That should work in all browsers.
A couple of things I've noted.
a) The click event on the submit button returns false. Returning false cancels the default action of an event, so in this case returning false would mean do not submit the form.
b) Your script sets window.location, which will immediately cause the browser to load the new page, and not submit the form at all.
精彩评论