views:

464

answers:

3

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?

A: 

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.

Andy Hume
but it works in FF, Chrome and Safari as is so I'm a bit confused as to why it doesn't work in IE?
Jonathan Lyon
What work's in Firefox? As far as I can see the browser just reloads with /questions/ask as the URL. What makes you think a form get's submitted?
Andy Hume
when you press enter in the inputbox it takes you to the questions/ask page and adds the content into the 'Title of Question' Field in all browsers but IE
Jonathan Lyon
+1  A: 

The right call to change the URL is window.location.href = "[url]", AFAIK.

Bora
+1  A: 

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.

Roosmaa
Hi Roosmaa unfortunately that didn't work - I tied onSubmit with and without the return false and it failed. You are right about tabbing to the hidden submit button and hitting enter - that works - is there a way of emulating this in javacript:-psudeo code: On key press enter - if IE - tab to submit field - click
Jonathan Lyon