Solved

Variable Default for Input

Posted on 2004-08-23
7
185 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
attribute vs parameter and setter vs add method 17 83
servlet cookie finding by name 1 70
doubleChar java challenge 7 102
Retrieving file from bytes array in spring mvc 8 59
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

12 Experts available now in Live!

Get 1:1 Help Now