?
Solved

Variable Default for Input

Posted on 2004-08-23
7
Medium Priority
?
193 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 28

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
Industry Leaders: 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 500 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 28

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

Industry Leaders: 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

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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