473,809 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set text field works on Safari not Firefox

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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><titl e>Untitled Document</title>
<script>
function set_text()
{
myform.mytext.v alue =
myform.myscroll .options[myform.myscroll .selectedIndex].text;

}

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

<select name="myscroll" size="7" onchange="set_t ext()">
<option value="laborato ry report">laborat ory report</option>
<option value="speciali st consult note">specialis t consult
note</option>
<option value="hospital discharge summary">hospit al discharge
summary</option>
<option value="ER discharge">ER discharge</option>
<option value="medical records">medica l records</option>
<option value="prescrip tions">prescrip tions</option>
<option value="audio dictation">audi o dictation</option>
</select>
<br />
<input type="text" name="mytext" />
<div>
<input type="hidden" name=".cgifield s" value="myscroll " />
</div>
</form>
</body></html>

Jul 23 '05 #1
4 2471
ione...@yahoo.c om 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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><titl e>Untitled Document</title>
<script>
function set_text()
{
myform.mytext.v alue =
myform.myscroll .options[myform.myscroll .selectedIndex].text;

}

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

<select name="myscroll" size="7" onchange="set_t ext()">
<option value="laborato ry report">laborat ory report</option>
<option value="speciali st consult note">specialis t consult
note</option>
<option value="hospital discharge summary">hospit al discharge
summary</option>
<option value="ER discharge">ER discharge</option>
<option value="medical records">medica l records</option>
<option value="prescrip tions">prescrip tions</option>
<option value="audio dictation">audi o dictation</option>
</select>
<br />
<input type="text" name="mytext" />
<div>
<input type="hidden" name=".cgifield s" 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_t ext(this)">

function set_text(obj)
{
var el;
if (el = obj.form.elemen ts.mytext)
el.value = obj.options[obj.selectedInd ex].text;
}

Jul 23 '05 #2
io*****@yahoo.c om 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.v alue =
myform.myscroll .options[myform.myscroll .selectedIndex].text;
}

</script>


function set_text(){
var f=document.myFo rm;
f.mytext.value =
f.myscroll.opti ons[f.myscroll.sele ctedIndex].text;
}
Mick

[snip]

}
Jul 23 '05 #3

RobB wrote:
ione...@yahoo.c om 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.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><titl e>Untitled Document</title>
<script>
function set_text()
{
myform.mytext.v alue =
myform.myscroll .options[myform.myscroll .selectedIndex].text;

}

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

<select name="myscroll" size="7" onchange="set_t ext()">
<option value="laborato ry report">laborat ory report</option>
<option value="speciali st consult note">specialis t consult
note</option>
<option value="hospital discharge summary">hospit al discharge
summary</option>
<option value="ER discharge">ER discharge</option>
<option value="medical records">medica l records</option>
<option value="prescrip tions">prescrip tions</option>
<option value="audio dictation">audi o dictation</option>
</select>
<br />
<input type="text" name="mytext" />
<div>
<input type="hidden" name=".cgifield s" 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_t ext(this)">

function set_text(obj)
{
var el;
if (el = obj.form.elemen ts.mytext)
el.value = obj.options[obj.selectedInd ex].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

Jul 23 '05 #4
io*****@yahoo.c om 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.dt d">
<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>Untitl ed 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.or g/>
function set_text()
{
myform.mytext.v alue =
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.selec tedIndex].text;
}
</script>
</head><body>
<form method="post" action="/./s.pl" ^^^^^^^
That's voodoo. "/s.pl" will suffice.
[...]
<select name="myscroll" size="7" onchange="set_t ext(this.form)" >


Replace with

<select name="myscroll" size="7" onchange="set_t ext(this.form)" >
PointedEars
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2255
by: lkrubner | last post by:
I've got a function, you can see it below, that is being called onmouseup in the textarea on my main form. The idea is to find a selection if possible and store that text in a global variable. I can't get this to work in any browser on a Mac, though it works alright on a PC. What am I missing?
14
3139
by: Eric Lindsay | last post by:
I've seen a page using display, and especially display table that did some neat things with boxes, but basically it only worked with Mozilla browsers. Fell over fairly badly with Opera and Safari (I don't have IE, but I have my suspicions that wouldn't work either). I'd like to use CSS to put some boxes down the middle of a page. The page is intended to be fluid, but the boxes all need to be the same width, which can be variable...
7
3273
by: Eric Lindsay | last post by:
I would like to do a photo gallery with a liquid layout. I wanted to center a caption below each photo (or above each photo). I can do that easily with tables, but then I don't have a liquid layout. Besides, I wanted to try to do it with CSS. I can do centered captions with text-align. This works provided the element containing each photo is floated left. I have found several examples of how to do this. However I didn't want the...
10
3525
by: Eric Lindsay | last post by:
This may be too far off topic, however I was looking at this page http://www.hixie.ch/advocacy/xhtml about XHTML problems by Ian Hickson. It is served as text/plain, according to Firefox Response Headers - http://www.hixie.ch/advocacy/xhtml Date: Wed, 23 Nov 2005 21:36:06 GMT Server: Apache/1.3.33 (Unix) DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.3.10 mod_ssl/2.8.22 OpenSSL/0.9.7e Vary: Accept-Encoding,User-agent
4
5629
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in FireFox and Safari it appears as a narrow column of text with only 2-3 words per line. Here is the code: function showAll()
1
1617
by: Limbo | last post by:
Hi, Using the following code to fill a specific text box on a form with an image file name. The code is called from a pop up window, fills a text box on the partent window and then the pop up window is closed. function pickImage(theImageName,theTextBoxName) { window.opener.document.getElementById(theTextBoxName).value = theImageName; self.close(); }
2
2753
by: JDeats | last post by:
>From my development envrionment (i.e. a single WinXP notebook PC) I have a basic AJAX application that is making the call to a Windows Form page that just returns the request back to the AJAX client from the JavaScript HttpXMLRequest protected void Page_Load(object sender, EventArgs e) { string txt = ""; string input = null;
3
4325
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in the text field remains empty. The page containing this problem is at the following location: http://www.skicow.com/component/option,com_skicow/act,shop/Itemid,51/debug_enabled,true The last parameter enables debug which results in alerts...
13
3331
by: Stevo | last post by:
I've found that for IE6+, if you add the property text-align:center to a DIV, then *anything* inside it gets centered. That can be a table, an object/embed, another DIV, an image, or some text. Firefox and Safari on the other hand don't treat text-align in that way. In my tests on those browsers, they only centers images and text. Any DIVs, object/embeds or tables remain default unaligned and generally appear on the left. Considering...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10639
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.