Hi All,
Been learning Javascript (via google) to create forms with pre-set values.
As seen below. My problem I have found is this: I can't seem to figure out
(or find so far via google) how to preset form options when the input type
is a radio button, or dropdown list. The same method does not seem to work
with input fields.
Anyone know of such a comprehensive site?
Thanks ahead,
Daniel
<FORM name="PersProf" action="newuser .pl" method="POST">
<table border="0">
<tr>
<td WIDTH="200">
First Name
</td>
<td>
<input type="text" name="first_nam e" maxlength=32 size = 32>
</td>
</tr>
</table>
<script language="JavaS cript">
<!--
//setting the value:
document.PersPr of.first_name.v alue = '$first_name';
-->
</script> 12 1967
daniel kaplan wrote: My problem I have found is this: I can't seem to figure out (or find so far via google) how to preset form options when the input type is a radio button, or dropdown list. The same method does not seem to work with input fields.
Do you mean preselected:
<input type="radio" checked> and
<option selected value="val">tex t</option>
On Sat, 11 Dec 2004 09:45:59 -0500, daniel kaplan <no****@nospam. com>
wrote: Hi All,
Been learning Javascript (via google) to create forms with pre-set values.
You don't specify initial values with Javascript. You specify them in HTML:
<input type="text" ... value="initial value">
<input type="checkbox" ... checked>
<input type="radio" ... checked>
<select ...>
<option ... selected>...</option>
</select>
<textarea ...>initial value</textarea>
I suggest you read the HTML Specification
(<URL:http://www.w3.org/TR/html4/>), rather than rely on the Web.
Information regarding forms can be found under section 17
(<URL:http://www.w3.org/TR/html4/interact/forms.html>).
If you have any further problems, please ask in alt.html or
comp.infosystem s.www.authoring.html.
[snip]
<script language="JavaS cript">
The language attribute has been deprecated for over six years. Use the
type attribute instead:
<script type="text/javascript">
<!--
Hiding scripts with SGML comment delimiters is an obsolete practice. It's
not necessary.
//setting the value: document.PersPr of.first_name.v alue = '$first_name';
The preferred way to access form controls is via the forms and elements
collections:
document.forms['form-id'].elements['control-name-or-id']
[snip]
Good luck,
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opsium76g8 x13kvk@atlantis ... You don't specify initial values with Javascript. You specify them in
HTML:
i guess since i was able to set the initial value of a TEXT field using
javascript, that i could do the same with ALL fields in the form...
and i using perl to generate the HTML dynamically, so my perl build the
html, with javascript included...
i can set them using HTML, but to do it dynamcially i turned to java....
strange that it allows me to do it for text and nothing else, no?
daniel
"daniel kaplan" wrote i guess since i was able to set the initial value of a TEXT field using javascript, that i could do the same with ALL fields in the form...
Being able to do something is never a good reason to go do it. In
programming the question should be: is it necessary? Here the answer is a
crystal clear no, see below.
and i using perl to generate the HTML dynamically, so my perl build the html, with javascript included...
i can set them using HTML, but to do it dynamcially i turned to java....
Java? I didn't see any java in your earlier code. It 's javascript, a
totally different and independent language. The names are confusing,
no one disagrees with that, but the environments in which they operate,
are incomparable, even within the same webbrowser.
strange that it allows me to do it for text and nothing else, no?
It does allow you to do it for all types of input elements. The point is
that you don't need javascript at all. Let your perl script write the values
directly in the value attributes of the elements. From your first post I
gather that in the perl syntax it would look like this:
<input type="text" name="first_nam e" value="$first_n ame">
Look Ma, no javascript!
--
Ivo http://www.vansandick.com/
"Ivo" <no@thank.you > wrote in message
news:41******** **************@ news.wanadoo.nl ... Being able to do something is never a good reason to go do it.
well, it seemed that javascript was rich Forms features. of course am
totally new to it, so that is how it appears to me, it coudl be wrong
Java? I didn't see any java in your earlier code.
obviously i typo'ed there
It does allow you to do it for all types of input elements.
do you know a decent website which points this out? even if i don't end up
using that part of it, i would still like to learn it.
The point is that you don't need javascript at all. Let your perl script
write the values directly in the value attributes of the elements. From your first post I gather that in the perl syntax it would look like this:
<input type="text" name="first_nam e" value="$first_n ame">
that is how i started...but when it came to other forms features such as a
drop down list of states, where one might already be sleceted, it obviously
was going to be much more coding. i.e. (OPTION vs. SELECTED) so that's why
i turned to look at javascript.
thanks,
daniel
daniel kaplan wrote: "Ivo" <no@thank.you > wrote in message news:41******** **************@ news.wanadoo.nl ...
The point is that you don't need javascript at all. Let your perl script write the values directly in the value attributes of the elements. From your first post I gather that in the perl syntax it would look like this:
<input type="text" name="first_nam e" value="$first_n ame">
that is how i started...but when it came to other forms features such as a drop down list of states, where one might already be sleceted, it obviously was going to be much more coding. i.e. (OPTION vs. SELECTED) so that's why i turned to look at javascript.
Hava Perl generate the select element. As it loops through the elements
of an array to create it, have it check the value, if they match, then
add the selected.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
"Randy Webb" <Hi************ @aol.com> wrote in message
news:vM******** ************@co mcast.com... Hava Perl generate the select element. As it loops through the elements of an array to create it, have it check the value, if they match, then add the selected.
well i am doing that with a lot of Ternery statements, because i am using
perl to build out the entire HTML page...it's just messy, so i assumed that
using javascript to do it at the end would have been cleaner
"Randy Webb" wrote daniel kaplan wrote:" "Ivo" <no@thank.you > wrote Being able to do something is never a good reason to go do it. well, it seemed that javascript was rich Forms features. of course am totally new to it, so that is how it appears to me, it coudl be wrong
The rule applies to all things. As far as javascript is concerned, you 'll
stop being new after reading the FAQ of this newsgroup http://www.jibbering.com/faq/
and related documents, and you understand why the sport is to rely on
javascript as little as possible. You control what happens on the server,
but when a page reaches the client, you just don't know what browser on what
OS is claiming to be some other browser, scripts may even be rewritten by
proxies and plugins (think popup blockers) and by the user himself. Most
importantly, a lot of people surf with javascript disabled or simply not
available, by choice or otherwise (estimates vary between 5%-25%). So you
want your page to be complete when you send it, and use javascript only for
things that are impossible without javascript.
Hava Perl generate the select element. As it loops through the elements of an array to create it, have it check the value, if they match, then add the selected.
Here is how I do them in PHP:
<?
function writeselect($na me,$atb='',$ops =array(),$sel=' '){
$s='<select name="'.$name.' " id="'.$name.'" '.$atb.'>';
$t=0; foreach($ops as $n=>$v) { $s.='<option
value="'.($t=== $n?$v:$n).'"'.( ($v==$sel)?' selected':'').' >'.$v; $t++;}
return $s.'</select>';
}
?>
<label for="cat" title="Grouping by topic">Category : </label>
<?=writeselect( 'cat','class="p ut"',array('Art ', 'Business',
'Computing', 'General', 'Travel'),'Gene ral');?>
<?=writeselect( 'amount','oncha nge="foo(this); "',array('Amoun t', 1=>'One',
12=>'Dozen'));? >
--
Ivo http://4umi.com/web/javascript/
daniel kaplan wrote: "Randy Webb" <Hi************ @aol.com> wrote in message news:vM******** ************@co mcast.com...
Hava Perl generate the select element. As it loops through the elements of an array to create it, have it check the value, if they match, then add the selected.
well i am doing that with a lot of Ternery statements, because i am using perl to build out the entire HTML page...it's just messy, so i assumed that using javascript to do it at the end would have been cleaner
As Ivo has said, never rely on JS. Use it as an addition but never a
requirement.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: |
last post by:
Hi,
I am setting the NumericUpDown .Value property and the ValueChanged event
is NOT being fired. Does this ONLY get fired when I change it on the UI and
not programatically?
Thanks
|
by: DotNetDummy |
last post by:
Hi all,
I am trying to set the printing setting e.g duplex mode etc. on a
default printer when I.E object started printing a particular html
doc.
Here's the partial code, any help would be appreciated.
I have been using system.drawing.printing method but not much help
since drawing.printing required printDocument() object which specially
|
by: dsnyder |
last post by:
This HTML has a bit of Javascript at the end that puts the initial
focus on the userID field. It works great on Windows2000 running IE6,
but the initial focus never goes to the userID field on Windows 2003
PocketPC (Windows Mobile) running Pocket IE.
<html><head><title>WMS - P280WF100 - Login</title><META
HTTP-EQUIV='expires' VALUE='0'>
</head>
<body>
<form name="frmLogon" action='p280wp100' method='get'>
|
by: Hasan Ammar |
last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be
done with the usual alphanumeric keys, but what about function keys?
or using ctrl/alt combinations? Does anybody have a tutorial/guide?
|
by: Bob |
last post by:
I'm a total newbie at Javascript, but a programmer for over 20 years...
so, my plans may be bigger than they are possible.
I'm trying to set with Javascript the value of a form field... easy
enough, right?
e.g. this successfully sets the local form's field:
document.thetestform.mycity.value='paris';
| |
by: Shravan |
last post by:
Hi,
I have a Windows Forms Custom DataGrid, which is put in a
usercontrol, which on setting DataSource is setting focus
to grid. The call stack for setting the focus is as
follows. This is not happened always whenever DataSource
is set, only called sometimes, in a series of setting
DataSource, I could get this setting focus only one time .
Can anybody help me how to stop this one.
system.windows.forms.dll!
|
by: Andy Fish |
last post by:
Hi,
I want to generate a value with javascript and include it in the form
postback for a web form.
based on my previous web development experience, I think I need an <input
type=hidden> on the page. However, to fit in properly with the web forms
paradigm, I would like this to be a proper asp.net server side control
rather than just generating it in the HTML.
|
by: jason |
last post by:
Hello and Good Day. REALLY LOST.
Running ASP.NET 1.1
Becuase I think I'm using my own controls smartnavigation does not
appear to work for me.
Stardard issue: I've got a datagrid thats displaying pages and pages of
rows. When I edit some row below pages 1 the post refreshes back to
page one, requiring me to page down to do the input.
|
by: PJ6 |
last post by:
From a control's onkeypress the below javascript snippet is executed. I am
attmpting to set the value of a hidden field... I believe I'd be able to get
the contents of the hidden field by using
"Page.Request.Item(MyHiddenFieldName)" sever-side, no? Unfortunately the
field doesn't look like it's even being set. Is there something special I
need to do?
TIA,
Paul
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |