Feb 27, 2006

PHP/ HTML: Calling Forms

I've a form where user can click a Find button. Another form is opened in new window and user can select one of possible values.
When user Select a value, it is passed into the field at the calling form.

This is the main form:

<tr> <td width=25%>Type:</td><td><input type=\"text\" name=\"type\" size=20> <input type=\"submit\" name=\"typesubmit\" value=\"Find\" onClick=\"window.open('./search.php?', '_gltypesearch', 'HEIGHT=300,resizable=yes,WIDTH=600');return false;\" /> </td> </tr>

This is the function (in popup form) that sends the selected value to Main Form:

function refresh_name(selected_name) { opener.document.forms[0].type.value = selected_name; opener.focus(); window.close(); }

And the Select Option is like this:

<select name=\"name_list\"> <option>A</option> <option>B</option> </select> <input type=\"submit\" onClick=\"refresh_name(this.form.name_list.options[this.form.name_list.selectedIndex ].value);return false;\" name=\"use\" value=\"Select\" />

This worked fine in FireFox. But didn't worked in Internet Explorer. I found one suggestion that asked to qualify opener object with window ( window.opener.document...). It didn't worked either for IE.

It worked when I put value clause within option tag, like this,
<option value='A'>A</option>
<option value='B'>B</option>
Lesson 1: Never forget the value clause in form controls.
Lesson 2: FF is better than IE. What works in FF may not work in IE.

ajaysajay

No comments: