Solved

Variable Default for Input

Posted on 2004-08-23
7
189 Views
Last Modified: 2010-04-01
How can I provide a variable default 'value' for HTML input?  Here's some sample code...

  <input name="Name" size="30" value="Scheduling">

Above, the prompted default value for the user is 'Scheduling.'  This means that every time the webpage is called up, 'Scheduling' is present as the default answer. What I want to do is replace ... value='Scheduling'...  with someting like  ... value=EnvironmentVariable ...

I think that this can't be done if the page is HTML.  But, is it done with embedded Javascript?  Or, do I need to convert page to JSP?  

This seems so elementary that I'm surprised that I'm not finding the answer!
0
Comment
Question by:LarryAndro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 11877159
>EnvironmentVariable  
Please give more details ?  What is this variable ? Why can't you use the following ?

<input name="Name" size="30" value="<%=EnvironmentVariable%>">
rrz
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 11877505
I've tried two variations on what you suggested...

<input name="Name" size="30" value="<%=parent.theMenu.entry[selectedEntry].text%>" readonly></td>               (with quotes)

and

<input name="Name" size="30" value=<%=parent.theMenu.entry[selectedEntry].text%> readonly></td>               (without quotes)

With no luck.  The <%=...> prints instead of the value of parent.theMenu.entry[selectedEntry].txt.  (And, the value of this variable exists; I can display it via alert.)

0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11877532
you need to do with javascript, here is an example.

<html>
  <script language="javascript">
    var a="a";
    var b="b";
  </script>
<body>
  <form name="form1">
    <input type="text" name="text1" value="default">
    <input type="button" value="change to a" onclick="document.

form1.text1.value=a;">
    <input type="button" value="change to b" onclick="document.

form1.text1.value=b;">
    <input type="reset" value="restore default">
  </form>
</body>
</html>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 125 total points
ID: 11877539
sorry for new-line, try this.

<html>
  <script language="javascript">
    var a="a";
    var b="b";
  </script>
<body>
  <form name="form1">
    <input type="text" name="text1" value="default">
    <input type="button" value="change to a" onclick="document.form1.text1.value=a;">
    <input type="button" value="change to b" onclick="document.form1.text1.value=b;">
    <input type="reset" value="restore default">
  </form>
</body>
</html>
0
 
LVL 27

Expert Comment

by:rrz
ID: 11877602
Sorry, I thought the variable was on your server.                   rrz
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 11877708
sompol_kiatkamolchai...

Your code above didn't do exactly what I wanted, which was to automatically load a default value without user interaction, at page load.  But, it did show me the technique to use, which I'm sure was your intent.

Here's my modified code...

<html>
  <script language="javascript">
    var a="a";
    var b="b";
  </script>
<body>
  <form name="form1">
    <input type="text" name="text1">
  </form>
  <script language="javascript">
        document.form1.text1.value=a;
  </script>
</body>
</html>

I stripped out a lot, and added the javascript after </form> and all's well.  The value held in the a variable loads automatically into the input box as a default.  

Followup question...  

Did I put the javascript code at the best place?
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11877729
I'm not sure what is the purpose of your code. but your code is ok, you can do like that.

:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
J2SE 5.0 metadata 1 67
doubleChar java challenge 7 129
throw exception 21 67
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question