Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > set text field works on Safari not Firefox

Reply
Thread Tools

set text field works on Safari not Firefox

 
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      04-27-2005
I am trying to do the basic task of setting a text field from the
choice made from a select box. I learned how to code it from my
O'Reilly Javascript reference which is a few years old. The code works
as expected in Safari but not Firefox which is where I really need it
to work primarily. Of course, I would like it to work everywhere. I
would greatly appreciate it if someone could point out my error. I did
check to make sure that all javascript functionality is enabled in
Firefox. Thank you!

wana

The code (generated by the perl module CGI.pm):

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><title>Untitled Document</title>
<script>
function set_text()
{
myform.mytext.value =
myform.myscroll.options[myform.myscroll.selectedIndex].text;

}

</script>
</head><body>
<form method="post" action="/./s.pl"
enctype="application/x-www-form-urlencoded" name="myform">

<select name="myscroll" size="7" onchange="set_text()">
<option value="laboratory report">laboratory report</option>
<option value="specialist consult note">specialist consult
note</option>
<option value="hospital discharge summary">hospital discharge
summary</option>
<option value="ER discharge">ER discharge</option>
<option value="medical records">medical records</option>
<option value="prescriptions">prescriptions</option>
<option value="audio dictation">audio dictation</option>
</select>
<br />
<input type="text" name="mytext" />
<div>
<input type="hidden" name=".cgifields" value="myscroll" />
</div>
</form>
</body></html>

 
Reply With Quote
 
 
 
 
RobB
Guest
Posts: n/a
 
      04-27-2005
ione...@yahoo.com wrote:
> I am trying to do the basic task of setting a text field from the
> choice made from a select box. I learned how to code it from my
> O'Reilly Javascript reference which is a few years old. The code

works
> as expected in Safari but not Firefox which is where I really need it
> to work primarily. Of course, I would like it to work everywhere. I
> would greatly appreciate it if someone could point out my error. I

did
> check to make sure that all javascript functionality is enabled in
> Firefox. Thank you!
>
> wana
>
> The code (generated by the perl module CGI.pm):
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
> xml:lang="en-US"><head><title>Untitled Document</title>
> <script>
> function set_text()
> {
> myform.mytext.value =
> myform.myscroll.options[myform.myscroll.selectedIndex].text;
>
> }
>
> </script>
> </head><body>
> <form method="post" action="/./s.pl"
> enctype="application/x-www-form-urlencoded" name="myform">
>
> <select name="myscroll" size="7" onchange="set_text()">
> <option value="laboratory report">laboratory report</option>
> <option value="specialist consult note">specialist consult
> note</option>
> <option value="hospital discharge summary">hospital discharge
> summary</option>
> <option value="ER discharge">ER discharge</option>
> <option value="medical records">medical records</option>
> <option value="prescriptions">prescriptions</option>
> <option value="audio dictation">audio dictation</option>
> </select>
> <br />
> <input type="text" name="mytext" />
> <div>
> <input type="hidden" name=".cgifields" value="myscroll" />
> </div>
> </form>
> </body></html>


The script engine is unable to resolve the reference to 'myform' as
it's neither a global variable (in good browsers) nor local to the
function. You'll need to prepend document. to the reference to qualify
it properly (document.forms. would be even better).

Since you're calling that function from the Select.onchange property,
with the Select object no farther away than the 'this' keyword, why not
pass it (along with its .form property)?

<select name="myscroll" size="7" onchange="set_text(this)">

function set_text(obj)
{
var el;
if (el = obj.form.elements.mytext)
el.value = obj.options[obj.selectedIndex].text;
}

 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      04-27-2005
wrote:

> I am trying to do the basic task of setting a text field from the
> choice made from a select box. I learned how to code it from my
> O'Reilly Javascript reference which is a few years old. The code works
> as expected in Safari but not Firefox which is where I really need it
> to work primarily.


[snip]
>
> The code (generated by the perl module CGI.pm):


> function set_text()
> {
> myform.mytext.value =
> myform.myscroll.options[myform.myscroll.selectedIndex].text;
> }
>
> </script>


function set_text(){
var f=document.myForm;
f.mytext.value =
f.myscroll.options[f.myscroll.selectedIndex].text;
}
Mick

[snip]

}


 
Reply With Quote
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      04-27-2005

RobB wrote:
> ione...@yahoo.com wrote:
> > I am trying to do the basic task of setting a text field from the
> > choice made from a select box. I learned how to code it from my
> > O'Reilly Javascript reference which is a few years old. The code

> works
> > as expected in Safari but not Firefox which is where I really need

it
> > to work primarily. Of course, I would like it to work everywhere.

I
> > would greatly appreciate it if someone could point out my error. I

> did
> > check to make sure that all javascript functionality is enabled in
> > Firefox. Thank you!
> >
> > wana
> >
> > The code (generated by the perl module CGI.pm):
> >
> > <?xml version="1.0" encoding="iso-8859-1"?>
> > <!DOCTYPE html
> > PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> > <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
> > xml:lang="en-US"><head><title>Untitled Document</title>
> > <script>
> > function set_text()
> > {
> > myform.mytext.value =
> > myform.myscroll.options[myform.myscroll.selectedIndex].text;
> >
> > }
> >
> > </script>
> > </head><body>
> > <form method="post" action="/./s.pl"
> > enctype="application/x-www-form-urlencoded" name="myform">
> >
> > <select name="myscroll" size="7" onchange="set_text()">
> > <option value="laboratory report">laboratory report</option>
> > <option value="specialist consult note">specialist consult
> > note</option>
> > <option value="hospital discharge summary">hospital discharge
> > summary</option>
> > <option value="ER discharge">ER discharge</option>
> > <option value="medical records">medical records</option>
> > <option value="prescriptions">prescriptions</option>
> > <option value="audio dictation">audio dictation</option>
> > </select>
> > <br />
> > <input type="text" name="mytext" />
> > <div>
> > <input type="hidden" name=".cgifields" value="myscroll" />
> > </div>
> > </form>
> > </body></html>

>
> The script engine is unable to resolve the reference to 'myform' as
> it's neither a global variable (in good browsers) nor local to the
> function. You'll need to prepend document. to the reference to

qualify
> it properly (document.forms. would be even better).
>
> Since you're calling that function from the Select.onchange property,
> with the Select object no farther away than the 'this' keyword, why

not
> pass it (along with its .form property)?
>
> <select name="myscroll" size="7" onchange="set_text(this)">
>
> function set_text(obj)
> {
> var el;
> if (el = obj.form.elements.mytext)
> el.value = obj.options[obj.selectedIndex].text;
> }



Thank you! It makes sense now. I cannot blame my old book for my
mistake, just myself for not paying attention. Thanks for the
information and insight. And thanks to all for helpful responses.

wana

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      05-08-2005
wrote:

> I am trying to do the basic task of setting a text field from the
> choice made from a select box. [...] The code works
> as expected in Safari but not Firefox which is where I really need it
> to work primarily. [...]
> The code (generated by the perl module CGI.pm):
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
> xml:lang="en-US">


XHTML 1.0 Transitional is voodoo. If you don't want clean markup, why are
you using XHTML anyway? There is nothing in your document that requires
it, especially not the deprecated elements and attributes. Use Valid HTML
4.01 Transitional or Strict (I recommend the latter) instead.

> <head>
> <title>Untitled Document</title>

^^^^^^^^^^^^^^^^^
That's a joke, yes?

> <script>


The `type' attribute is missing, both if should be Valid HTML 4 and Valid
XHTML. Validate your markup before you complain: <http://validator.w3.org/>

> function set_text()
> {
> myform.mytext.value =
> myform.myscroll.options[myform.myscroll.selectedIndex].text;
> }


Replace with

function set_text(f)
{
var o = f.elements["myscroll"];
f.elements["mytext"].value = o.options[o.options.selectedIndex].text;
}

> </script>
> </head><body>
> <form method="post" action="/./s.pl"

^^^^^^^
That's voodoo. "/s.pl" will suffice.

> [...]
> <select name="myscroll" size="7" onchange="set_text(this.form)">


Replace with

<select name="myscroll" size="7" onchange="set_text(this.form)">


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My movement of banner is not working in IE6, works in IE7 and Firefox, and Safari Terry Javascript 1 10-20-2007 09:38 PM
AJAX app will not make call on Safari and FireFox, works fine on Internet Explorer, any ideas? JDeats ASP .Net 2 09-11-2007 10:20 PM
Position layers works in IE not Firefox/Safari cewisham@yahoo.com Javascript 11 04-28-2006 04:21 AM
JavaScript not working in IE and Safari, works in Firefox fine. dpodkuik@gmail.com Javascript 4 02-18-2006 12:51 AM
Disabling a text field by clicking an option (works with Firefox but not with IE6) Mark Noten Javascript 1 12-28-2005 09:52 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57