Solved

Variable Default for Input

Posted on 2004-08-23
7
184 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Expert Comment

by:rrz
Comment Utility
>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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 125 total points
Comment Utility
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
Comment Utility
Sorry, I thought the variable was on your server.                   rrz
0
 
LVL 1

Author Comment

by:LarryAndro
Comment Utility
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
Comment Utility
I'm not sure what is the purpose of your code. but your code is ok, you can do like that.

:)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now