[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Variable Default for Input

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

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

831 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