473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript for value attribute

Hi,

Can someone tell me what I'm doing wrong here? It makes sense to me,
but fails to actually execute the code. I can't find anything on
google, but maybe my search criteria are off.

<input type="text" name="amount" value=<script TYPE="text/javascript">
roundNumber(number, digits); </script>>

Thanks,

Brian

Jul 23 '05 #1
6 2337

brian.ackermann wrote:
Hi,

Can someone tell me what I'm doing wrong here? It makes sense to me,
but fails to actually execute the code. I can't find anything on
google, but maybe my search criteria are off.

<input type="text" name="amount" value=<script TYPE="text/javascript"> roundNumber(number, digits); </script>>

Thanks,

Brian


Hi Brian.

That 'value' attribute takes a string - you can't simply "plug in"
JavaScript anywhere and expect it to run. Read this:

http://d0om.fnal.gov/d0admin/doctaur...pt/ch12_02.htm

Jul 23 '05 #2
Yeah, so I am discovering.

I decided to build the whole input line in javascript:

<SCRIPT TYPE="text/javascript">
document.write("<INPUT TYPE='TEXT' NAME='AMOUNT'");
document.write(" VALUE='" + roundNumber(43.987654, 5) +"'");
document.write(">");
</SCRIPT>

Thanks. :D

Jul 23 '05 #3
In article <11**********************@z14g2000cwz.googlegroups .com>,
br*************@gmail.com enlightened us with...
Hi,

Can someone tell me what I'm doing wrong here? It makes sense to me,
but fails to actually execute the code. I can't find anything on
google, but maybe my search criteria are off.

<input type="text" name="amount" value=<script TYPE="text/javascript">
roundNumber(number, digits); </script>>


You can't do that...unless you're doing server-side stuff with

value="<%=expression%>"

or similar. Which may be where you got the notion this was even vaguely
possible.

Do this instead.
<input type="text" name="amount" value="">
<script TYPE="text/javascript">
document.formname.amount.value = roundNumber(number, digits);
</script>

Note that "number" and "digits" must be in scope, available at the time it
runs.

--
--
~kaeli~
Murphy's Law #2030: If at first you don't succeed, destroy
all evidence that you tried.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4
kaeli wrote:
[snip]

You can't do that...unless you're doing server-side stuff with

value="<%=expression%>"

or similar. Which may be where you got the notion this was even vaguely
possible.


In Netscape 4 you could use:

value= &{variable};

Aah, TWTD.
Mick

Jul 23 '05 #5
brian.ackermann wrote:
Yeah, so I am discovering.

I decided to build the whole input line in javascript:

<SCRIPT TYPE="text/javascript">
document.write("<INPUT TYPE='TEXT' NAME='AMOUNT'");
document.write(" VALUE='" + roundNumber(43.987654, 5) +"'");
document.write(">");
</SCRIPT>


That's a bit silly, you are creating a dependency on JavaScript that
is simply not required. Why not just use HTML?

<input type="text" name="amount" value="43.98765">

Then you have zero dependency on JavaScript. Presumably any rounding
required for the value can be done on the server when the value is
put into the page in the first place.

If you can't control what the server puts into the page, then run the
rounding function on page load. That way, everyone can seen the
value but those with JavaScript enabled will see the rounded value.

If you want a user-entered value to be rounded, then use an onchange
event.
--
Rob
Jul 23 '05 #6
brian.ackermann wrote:
I decided to build the whole input line in javascript:
Reconsider.
<SCRIPT TYPE="text/javascript">
document.write("<INPUT TYPE='TEXT' NAME='AMOUNT'");
document.write(" VALUE='" + roundNumber(43.987654, 5) +"'");
document.write(">");
</SCRIPT>


Consecutive calls of document.write() are inefficient and error-prone.
Try this instead:

document.write(
"<input name='AMOUNT'" value='" + roundNumber(43.987654, 5) + "'>");

or this:

document.write(
["<input name='AMOUNT'" value='", roundNumber(43.987654, 5), "'>"]
.join(""));
PointedEars
Jul 23 '05 #7

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

Similar topics

0
7054
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
12
1529
by: Tom | last post by:
Hi all, I am a newbe to javascript so I could use your help. I checked the FAQs and searched google but I could not resolve this problem. My form is as follows: <form...
15
4181
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
136
9201
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
8
3623
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
6
1897
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
8
3697
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
9
8388
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
17
2647
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
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,...
0
7376
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...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
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...
0
5623
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,...
0
3191
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...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.